maruohon / litematica

A modern client-side schematic mod for Minecraft
GNU Lesser General Public License v3.0
730 stars 221 forks source link

1.17 Crash when trying to save large selections #372

Open BenjaminHoegh opened 3 years ago

BenjaminHoegh commented 3 years ago

Crash when trying to save large selections

Selection size: 1672 x 206 x 1369

[11:48:34] [Server thread/ERROR]: Encountered an unexpected exception
java.lang.NegativeArraySizeException: -30270786
    at fi.dy.masa.litematica.schematic.container.LitematicaBitArray.<init>(LitematicaBitArray.java:38) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.schematic.container.LitematicaBitArray.<init>(LitematicaBitArray.java:22) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.schematic.container.LitematicaBlockStateContainer.setBits(LitematicaBlockStateContainer.java:93) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.schematic.container.LitematicaBlockStateContainer.onResize(LitematicaBlockStateContainer.java:105) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.schematic.container.LitematicaBlockStatePaletteLinear.idFor(LitematicaBlockStatePaletteLinear.java:45) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.schematic.container.LitematicaBlockStateContainer.set(LitematicaBlockStateContainer.java:54) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.schematic.LitematicaSchematic.takeBlocksFromWorldWithinChunk(LitematicaSchematic.java:1058) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.scheduler.tasks.TaskSaveSchematic.processChunk(TaskSaveSchematic.java:64) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.scheduler.tasks.TaskProcessChunkBase.execute(TaskProcessChunkBase.java:51) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at fi.dy.masa.litematica.scheduler.TaskScheduler.runTasks(TaskScheduler.java:65) ~[litematica-fabric-1.17.0-0.0.0-dev.20210616.033538.jar:?]
    at net.minecraft.class_1132.handler$zkp000$onPostTick(class_1132.java:1036) ~[intermediary-minecraft-1.17-client.jar:?]
    at net.minecraft.class_1132.method_3748(class_1132.java:96) ~[intermediary-minecraft-1.17-client.jar:?]
    at net.minecraft.server.MinecraftServer.method_29741(MinecraftServer.java:692) ~[intermediary-minecraft-1.17-client.jar:?]
    at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:274) ~[intermediary-minecraft-1.17-client.jar:?]
    at java.lang.Thread.run(Thread.java:831) [?:?]
maruohon commented 3 years ago

See if this version fixes it: https://masa.dy.fi/tmp/minecraft/mods/misc_test_versions/litematica-fabric-1.17.0-0.0.0-dev.20210703.150412.jar

In general Litematica is not meant as a world downloader type of mod. It's not really suitable for that kind of use cases, because the entire schematic has to be loaded into memory at once, so with very large areas the memory requirements will get out of hand quickly. I'm not sure if that is the case here, or if you just have a really large build...

I would at the very least recommend splitting up the entire area into several smaller sub-regions, and especially avoid selecting large volumes of empty space. For example if you have one tall building in the area and otherwise half of the height of the selection everywhere else is just air, then use a separate sub-region to capture the part of that tall building that is above the bottom box that captures the base terrain, and make that bottom box a lot less tall. That will help both with memory requirements, and especially with the performance of saving the schematic and the bit array resize operations.