From acf507bb324ee95e77ba4710b57bc0351b1433fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 1 Aug 2024 12:09:22 +0200 Subject: [PATCH] SWF.getCharacters synchronization fix --- .../src/com/jpexs/decompiler/flash/SWF.java | 78 +++++++++---------- 1 file changed, 37 insertions(+), 41 deletions(-) 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 e38d82db8..ab6a279d4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -670,52 +670,48 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { di.getChildInfos().clear(); } - public Map getCharacters(boolean withImported) { - if (characters == null) { - synchronized (this) { - if (characters == null) { - if (destroyed) { - return new HashMap<>(); - } - Map chars = new HashMap<>(); - Map charsWithImported = new HashMap<>(); - Map> charIdtags = new HashMap<>(); - Map eimages = new HashMap<>(); - parseCharacters(getTags(), eimages, chars, charIdtags); - charsWithImported.putAll(chars); - for (int importedCharacterId : importedCharacterIds.keySet()) { - int exportedCharacterId = importedCharacterIds.get(importedCharacterId); - SWF importedSwf = importedCharacterSourceSwfs.get(importedCharacterId); - charsWithImported.put(importedCharacterId, importedSwf.getCharacter(exportedCharacterId)); - charIdtags.put(importedCharacterId, importedSwf.getCharacterIdTags(exportedCharacterId)); - //FIXME? eimages + public synchronized Map getCharacters(boolean withImported) { + if (characters == null || charactersWithImported == null) { + if (destroyed) { + return new HashMap<>(); + } + Map chars = new HashMap<>(); + Map charsWithImported = new HashMap<>(); + Map> charIdtags = new HashMap<>(); + Map eimages = new HashMap<>(); + parseCharacters(getTags(), eimages, chars, charIdtags); + charsWithImported.putAll(chars); + for (int importedCharacterId : importedCharacterIds.keySet()) { + int exportedCharacterId = importedCharacterIds.get(importedCharacterId); + SWF importedSwf = importedCharacterSourceSwfs.get(importedCharacterId); + charsWithImported.put(importedCharacterId, importedSwf.getCharacter(exportedCharacterId)); + charIdtags.put(importedCharacterId, importedSwf.getCharacterIdTags(exportedCharacterId)); + //FIXME? eimages - charsWithImported.get(importedCharacterId).setImported(true, true); - for (CharacterIdTag chi : charIdtags.get(importedCharacterId)) { - if (chi instanceof Tag) { - ((Tag) chi).setImported(true, true); - } - } + charsWithImported.get(importedCharacterId).setImported(true, true); + for (CharacterIdTag chi : charIdtags.get(importedCharacterId)) { + if (chi instanceof Tag) { + ((Tag) chi).setImported(true, true); } - Map charToId = new IdentityHashMap<>(); - for (int id : charsWithImported.keySet()) { - charToId.put(charsWithImported.get(id), id); - } - for (int id : charIdtags.keySet()) { - for (CharacterIdTag ch : charIdtags.get(id)) { - charToId.put(ch, id); - } - } - - characters = Collections.unmodifiableMap(chars); - charactersWithImported = Collections.unmodifiableMap(charsWithImported); - characterToId = Collections.unmodifiableMap(charToId); - characterIdTags = Collections.unmodifiableMap(charIdtags); - externalImages2 = Collections.unmodifiableMap(eimages); } } - } + Map charToId = new IdentityHashMap<>(); + for (int id : charsWithImported.keySet()) { + charToId.put(charsWithImported.get(id), id); + } + for (int id : charIdtags.keySet()) { + for (CharacterIdTag ch : charIdtags.get(id)) { + charToId.put(ch, id); + } + } + characters = Collections.unmodifiableMap(chars); + charactersWithImported = Collections.unmodifiableMap(charsWithImported); + characterToId = Collections.unmodifiableMap(charToId); + characterIdTags = Collections.unmodifiableMap(charIdtags); + externalImages2 = Collections.unmodifiableMap(eimages); + } + return withImported ? charactersWithImported : characters; }