gottsch/gottsch-minecraft-Dungeons2

CTD -- NPE -- DungeonsWorldGen.generate -- Stylesheet default resources fail to initialize properly on first launch

Opened this issue · 0 comments

crash-2022-07-29_17.41.29-server.txt
dungeons2.log

Steps to reproduce:

  1. Install a fresh Curse Modded Minecraft 1.12.2, Forge 14.23.5.2859 profile and install Dungeons2!, or Import the following profile:
    Dungeons2Test.zip
  2. Attempt to create a new, single-player world, with the seed: 1
  3. CTD

Note, CTD doesn't happen on subsequent launches of the same world, even after deleting the world and creating it again.
After a CTD, it doesn't seem that the dungeon at the spawn location effectively spawns. If you delete the world, then create a world with the same name and the seed (1), then the dungeon near the spawn does generate.

This led me to investigate the code further.
The Crash Log points to this:
at com.someguyssoftware.dungeons2.worldgen.DungeonsWorldGen.generate(DungeonsWorldGen.java:274)

Theme theme = styleSheet.getThemes().get(styleSheet.getThemes().keySet().toArray()[random.nextInt(styleSheet.getThemes().size())]);
// TODO create a custom exception to throw if theme is null/not found.

And the Dungeons2 Log points to this:
at com.someguyssoftware.dungeons2.style.StyleSheetLoader.exposeStyleSheet(StyleSheetLoader.java:249) [StyleSheetLoader.class:mc1.12.2-f14.23.5.2859-v1.7.6]

public static void exposeStyleSheet(String filePath) {
Path path = Paths.get(filePath).toAbsolutePath();
if (Files.notExists(path)) {
Dungeons2.log.error("Attempting to copy style to path -> {}", path.toString());
// TODO create folder
// copy from resource/classpath to file path
InputStream is = Dungeons2.instance.getClass().getResourceAsStream(StyleSheetLoader.BUILT_IN_STYLE_SHEET_PATH);
try (FileOutputStream fos = new FileOutputStream(path.toFile())) {
byte[] buf = new byte[2048];
int r;
while ((r = is.read(buf)) != -1) {
fos.write(buf, 0, r);
}
}
catch(IOException e) {
Dungeons2.log.error("Error exposing stylesheet resource to file system: ", e);
}
}
}

We know the try on L249 is failing, and we get this message:
java.io.FileNotFoundException: C:\Users\Twistedlink\Documents\Twitch\Minecraft\Instances\Dungeons2Test\mods\dungeons2\styleSheet.json (The system cannot find the path specified)

On a hunch, I created a second modpack, with an override to supply the contents of the mods/dungeons2 directory before first launch:
Dungeons2TestOverrides.zip

If you import and run this profile, things work as intended, suggesting there's an issue with the mod attempting to use these stylesheet resources before they're successfully initialized.

I don't have the time to dig further at the moment (I don't have a development environment set up to do mod development), and this overrides workaround works for me. Additionally, anyone running this mod for the first time will likely crash once, but on subsequent runs, will be fine. It hampers the initial user experience, but it isn't game-breaking, despite being a CTD.