Skip to content

Commit

Permalink
Fix crash when restarting preview threads
Browse files Browse the repository at this point in the history
Wait at most 5s for previous runner to stop so ui thread doesn't get locked if there was an error
Handle cases where TextureEntries are returned null due to thread interruption
  • Loading branch information
mmdanggg2 committed Jun 18, 2024
1 parent ee091e0 commit 22e761f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/org/jmc/BlockInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public Color getPreviewColor(BlockData blockData, NamespaceID biome)
} else {
te = Registries.getTexture(mtlNames[0]);
}
if (te == null) {
return Color.MAGENTA;
}
try {
return te.getAverageColour();
} catch (IOException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/org/jmc/gui/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ void stopPreviewLoader() {
if (chunk_loader_thread != null) {
chunk_loader_thread.interrupt();
try {
chunk_loader_thread.join();
chunk_loader_thread.join(5000);
} catch (InterruptedException e) {
Log.error("Interrupted waiting for preview chunk loader to stop!", e);
Thread.currentThread().interrupt();
Expand Down
2 changes: 1 addition & 1 deletion src/org/jmc/gui/ViewChunkLoaderRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void run() {
t.interrupt();
try {
t.join();
} catch (InterruptedException e) {}
} catch (InterruptedException ignored) {}
}
imagerThreads.clear();
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/jmc/models/Banner.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ private boolean generateBannerImage(NamespaceID materialImageName, ArrayList<Ban
Log.error("Cant read banner base image!", e, showReadErrorPopup());
return false;
}
if (backgroundImage == null) return false;

// todo - do something with the basecolor here...
// Log.info(" - Base Color: " + baseColorIndex);

Expand All @@ -257,6 +259,7 @@ private boolean generateBannerImage(NamespaceID materialImageName, ArrayList<Ban
BufferedImage patternSource;
try {
TextureEntry te = Registries.getTexture(new NamespaceID("jmc2obj", "banner/pattern_" + bp.getPattern()));
if (te == null) return false;
patternSource = te.getImage();
} catch (IOException e) {
Log.error("Cant read banner pattern " + bp.getPattern(), e, showReadErrorPopup());
Expand Down Expand Up @@ -306,6 +309,7 @@ private boolean generateBannerImage(NamespaceID materialImageName, ArrayList<Ban
}

TextureEntry texEntry = Registries.getTexture(materialImageName);
if (texEntry == null) return false;
texEntry.setImage(combined);
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/org/jmc/models/Head.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ private static boolean exportSkullOwnerTexture(TAG_Compound skullOwnerTag, Names
texture = expandedTex;
}
TextureEntry texEntry = Registries.getTexture(texId);
if (texEntry == null) {
return false;
}
texEntry.setImage(texture);
return true;
} catch (IOException e) {
Expand Down
1 change: 1 addition & 0 deletions src/org/jmc/registry/Registries.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public static ModelEntry getModel(NamespaceID id) {
return models.get(id);
}

@CheckForNull
public static TextureEntry getTexture(NamespaceID id) {
return textures.get(id);
}
Expand Down

0 comments on commit 22e761f

Please sign in to comment.