diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java index 7cd53dd3e..dd5e2c762 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java @@ -27,7 +27,13 @@ import com.jpexs.decompiler.flash.helpers.HighlightedText; import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.helpers.ImmediateFuture; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; import java.util.concurrent.Callable; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; @@ -44,6 +50,8 @@ public class DecompilerPool { private final ThreadPoolExecutor executor; + private Map>> swfToFutures = new WeakHashMap<>(); + public DecompilerPool() { int threadCount = Configuration.getParallelThreadCount(); executor = new ThreadPoolExecutor(threadCount, threadCount, @@ -148,6 +156,11 @@ public class DecompilerPool { public HighlightedText decompile(ASMSource src, ActionList actions) throws InterruptedException { Future future = submitTask(src, actions, null); + SWF swf = src.getSwf(); + if (!swfToFutures.containsKey(swf)) { + swfToFutures.put(swf, new ArrayList<>()); + } + swfToFutures.get(swf).add(future); try { return future.get(); } catch (InterruptedException ex) { @@ -155,6 +168,11 @@ public class DecompilerPool { throw ex; } catch (ExecutionException ex) { Logger.getLogger(DecompilerPool.class.getName()).log(Level.SEVERE, null, ex); + } finally { + List> futures = swfToFutures.get(swf); + if (futures != null) { + futures.remove(future); + } } return null; @@ -162,6 +180,12 @@ public class DecompilerPool { public HighlightedText decompile(ScriptPack pack) throws InterruptedException { Future future = submitTask(pack, null); + + SWF swf = pack.getSwf(); + if (!swfToFutures.containsKey(swf)) { + swfToFutures.put(swf, new ArrayList<>()); + } + swfToFutures.get(swf).add(future); try { return future.get(); } catch (InterruptedException ex) { @@ -169,6 +193,11 @@ public class DecompilerPool { throw ex; } catch (ExecutionException ex) { Logger.getLogger(DecompilerPool.class.getName()).log(Level.SEVERE, null, ex); + } finally { + List> futures = swfToFutures.get(swf); + if (futures != null) { + futures.remove(future); + } } return null; @@ -179,4 +208,13 @@ public class DecompilerPool { if (!executor.awaitTermination(100, TimeUnit.SECONDS)) { } } + + public void destroySwf(SWF swf){ + List> futures = swfToFutures.get(swf); + if(futures!=null){ + for(Future future:futures){ + future.cancel(true); + } + } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 55703db6e..390849498 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -375,6 +375,7 @@ public final class SWF implements SWFContainerItem, Timelined { } public void clearTagSwfs() { + decompilerPool.destroySwf(this); resetTimelines(this); updateCharacters(); @@ -408,7 +409,7 @@ public final class SWF implements SWFContainerItem, Timelined { for (ABCContainerTag c : abcList) { c.getABC().free(); } - abcList.clear(); + abcList = null; } if (swfList != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 1b3f9f659..79b09b09b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -122,7 +122,7 @@ public class ScriptPack extends AS3ClassTreeItem { return packageName; } - public Trait getPublicTrait() { + public Trait getPublicTrait() { for (int t : traitIndices) { Multiname name = abc.script_info.get(scriptIndex).traits.traits.get(t).getName(abc); Namespace ns = name.getNamespace(abc.constants); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index bfca9d1de..dbede7e84 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -989,8 +989,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se swfs.clear(); oldItem = null; clear(); - updateUi(); - + updateUi(); + for (SWFList swfList : swfsLists) { List swfs2 = new ArrayList<>(swfList); for (SWF swf : swfs2) { diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 8daedbf67..377d17704 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -53,6 +53,7 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.event.CaretEvent; @@ -752,8 +753,16 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL } catch (CancellationException ex) { setText("// " + AppStrings.translate("work.canceled")); } catch (Exception ex) { - logger.log(Level.SEVERE, "Error", ex); - setText("// " + AppStrings.translate("decompilationError") + ": " + ex); + Throwable cause = ex; + if (ex instanceof ExecutionException) { + cause = ex.getCause(); + } + if (cause instanceof CancellationException) { + setText("// " + AppStrings.translate("work.canceled")); + } else { + logger.log(Level.SEVERE, "Error", cause); + setText("// " + AppStrings.translate("decompilationError") + ": " + cause); + } } }); } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java index 0f724b5d0..2c4eaa7ca 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java @@ -562,6 +562,9 @@ public class TagTreeModel implements TreeModel { @Override public TreeItem getChild(Object parent, int index) { + if(getChildCount(parent) == 0) { + return null; + } TreeItem parentNode = (TreeItem) parent; if (parentNode instanceof CharacterTag) {