MovingBlocks / Terasology

Terasology - open source voxel world
http://terasology.org
Apache License 2.0
3.69k stars 1.34k forks source link

crash on loading a save with animals #5051

Open keturn opened 2 years ago

keturn commented 2 years ago

In current development versions of Terasology, I get a fatal crash whenever trying to load a save game with sheep or deer.

Traceback is something like this:

[main] ERROR o.t.engine.core.modes.StateLoading - Error while loading org.terasology.engine.core.modes.loadProcesses.LoadEntities@21f8693e
java.lang.NullPointerException: null
    at org.terasology.engine.rendering.logic.SkeletonRenderer.newSkeleton(SkeletonRenderer.java:110)
    […]
    at org.terasology.engine.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:190)
    at org.terasology.engine.entitySystem.entity.EntityBuilder.build(EntityBuilder.java:110)
    at org.terasology.engine.entitySystem.entity.internal.PojoEntityManager.createEntityWithId(PojoEntityManager.java:376)
    at org.terasology.engine.persistence.serializers.EntitySerializer.deserialize(EntitySerializer.java:168)
    at org.terasology.engine.persistence.internal.GlobalStoreLoader.load(GlobalStoreLoader.java:58)
    at org.terasology.engine.persistence.internal.AbstractStorageManager.loadGlobalStore(AbstractStorageManager.java:80)

The that's here: https://github.com/MovingBlocks/Terasology/blob/1f0349f4d6464cd4a831b70fb19a67ed41ad8ce1/engine/src/main/java/org/terasology/engine/rendering/logic/SkeletonRenderer.java#L107-L109

skeleton.boneEntities is non-empty, but all the references in it are EntityRef.NULL, so those have no LocationComponent.

I believe the null entity references come from here: https://github.com/MovingBlocks/Terasology/blob/2d0c434654b797b71e9a0d00004b3b79f3a4c5e7/engine/src/main/java/org/terasology/engine/persistence/typeHandling/extensionTypes/EntityRefTypeHandler.java#L33-L37

Is there some weird thing with loading the graph where those references are defined later in the global store, and they're not yet available when the deserializer tries to reference them?

it's also kinda weird that that's during GloabalStoreLoader, because I think those animals should be saved at chunk-level, not in the global store?

maybe their bones are in the chunk store but the rest of their SkeletalMeshComponent is in the global store?

keturn commented 2 years ago

Notes from #stabilization:

Niruandaleth failed to reproduce the problem.

A save game made on her system loads just fine here, which confirms the issue is in saving, not loading.

I tried reproducing on a second system, and found it was much rarer. Whereas I can reproduce it all the time on my normal development system, on that one it usually worked fine. It was only when I'd messed with some graphics settings and the deer were kinda glitching out while in the pause menu that it produced the broken save.

That was on Windows 10 with an i7-9700, compared to my usual Linux and i7-6700.

The working save file: savegame.tar.gz The same game, after loading and getting re-saved here: keturn_broke_the-savegame.tar.gz

keturn commented 2 years ago

Some of the corrupt data comes from https://github.com/MovingBlocks/Terasology/pull/5054

but perhaps not all of it.

My manual test involved going out and finding sheep, but that was taking too long, especially because spawn locations are not reproducible. So I've been trying other things.

It seems like starting a new game and doing spawnPrefab sheep is not sufficient to reproduce.

The bug may involve having sheep in chunks that you've already moved away from, or perhaps moving far enough away from 0, 0 that it's no longer currently loaded.

keturn commented 2 years ago

I believe this still exists but it I've found it a lot harder to reproduce since #5054 was merged.

I think I reproduced it once after walking > 13 chunks. Then I was trying to narrow it down to a faster scenario. Turning view distance down, messing with the WildAnimals spawn rate, turning LOD up or down, using the console to spawn a sheep... didn't come up with any obvious trigger actions for it. There were sometimes entity references that didn't get resolved on load, but they didn't turn in to crashers.

If this bug isn't popping up for other people, I'm willing to remove the Blocker label from it.