Fixed: #1636 Exception on reloading (7)

This commit is contained in:
Jindra Petřík
2021-03-09 23:05:43 +01:00
parent 9ddc983a03
commit 8c988646f7
6 changed files with 57 additions and 6 deletions

View File

@@ -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<SWF, List<Future<HighlightedText>>> 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<HighlightedText> 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<Future<HighlightedText>> 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<HighlightedText> 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<Future<HighlightedText>> 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<Future<HighlightedText>> futures = swfToFutures.get(swf);
if(futures!=null){
for(Future<HighlightedText> future:futures){
future.cancel(true);
}
}
}
}

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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<SWF> swfs2 = new ArrayList<>(swfList);
for (SWF swf : swfs2) {

View File

@@ -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);
}
}
});
}

View File

@@ -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) {