MovingBlocks / Terasology

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

null pointer exception in deserializating update from server #4112

Open keturn opened 4 years ago

keturn commented 4 years ago

What you were trying to do

join the playtest server during the fallingblocks + volcano test

What actually happened

12:28:29.770 [main] WARN  o.t.p.s.NetworkEntitySerializer - Skipping unknown component 59
12:28:29.773 [main] INFO  o.t.l.p.ThirdPersonRemoteClientSystem - Somehow ended up in the else during linkHeldItemLocationForRemotePlayer - current item was EntityRef{id=0} and new item EntityRef{id = 0}
12:28:29.821 [main] INFO  o.t.l.p.ThirdPersonRemoteClientSystem - Somehow ended up in the else during linkHeldItemLocationForRemotePlayer - current item was EntityRef{id=0} and new item EntityRef{id = 0}
12:28:29.829 [main] INFO  o.t.l.p.ThirdPersonRemoteClientSystem - Somehow ended up in the else during linkHeldItemLocationForRemotePlayer - current item was EntityRef{id=0} and new item EntityRef{id = 0}
12:28:29.846 [main] ERROR o.terasology.engine.TerasologyEngine - Uncaught exception, attempting clean game shutdown
java.lang.NullPointerException: null
    at org.terasology.network.serialization.NetComponentSerializeCheck.serialize(NetComponentSerializeCheck.java:31)
    at org.terasology.persistence.serializers.NetworkEntitySerializer.deserializeOnto(NetworkEntitySerializer.java:249)
    at org.terasology.persistence.serializers.NetworkEntitySerializer.deserializeOnto(NetworkEntitySerializer.java:203)
    at org.terasology.network.internal.ServerImpl.updateEntity(ServerImpl.java:377)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
    at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085)
    at org.terasology.network.internal.ServerImpl.processMessages(ServerImpl.java:272)
    at org.terasology.network.internal.ServerImpl.update(ServerImpl.java:186)
    at org.terasology.network.internal.NetworkSystemImpl.update(NetworkSystemImpl.java:319)
    at org.terasology.engine.subsystem.common.NetworkSubsystem.preUpdate(NetworkSubsystem.java:52)
    at org.terasology.engine.TerasologyEngine.tick(TerasologyEngine.java:461)
    at org.terasology.engine.TerasologyEngine.mainLoop(TerasologyEngine.java:431)
    at org.terasology.engine.TerasologyEngine.run(TerasologyEngine.java:407)
    at org.terasology.engine.Terasology.main(Terasology.java:164)
12:28:29.846 [main] INFO  o.terasology.engine.TerasologyEngine - Shutting down Terasology...
keturn commented 4 years ago

probably worth noting that I was on this server for a bit before I got this error, but after that I don't think was able to successfully re-join without running in to this immediately.

keturn commented 4 years ago

The line that encounters the null is NetComponentSerializeCheck: https://github.com/MovingBlocks/Terasology/blob/3815d963df90f9a16d65617c17ef635a2d817f86/engine/src/main/java/org/terasology/network/serialization/NetComponentSerializeCheck.java#L30-L31

so one option would be to add a null check there and return a constant default.

but I don't want to paper over symptoms if they're a sign of a deeper problem. Should that parameter be nullable at all?

IntelliJ IDEA thinks that a null in that spot most likely comes from here: https://github.com/MovingBlocks/Terasology/blob/8840b62d8f3402db71c214225e82ffabe70b5e20/engine/src/main/java/org/terasology/reflection/metadata/AbstractClassLibrary.java#L104-L106

that null check has been there forever.

I'm not sure what it would mean to have a null there. Does object.getClass() ever return null in java?

Cervator commented 4 years ago

Curious to get some thoughts from @eviltak on this issue. Not really wanting to paper symptoms over either, but on the other hand the entirety of the netcode probably really needs a bit of an overhaul sometime in the future, maybe as part of hooking up multiplayer for DS via shared lib then re-integrating the newer Gestalt pieces back into TS.

DarkWeird commented 3 years ago

@skaldarnar this is not Object.getClass return null, but custom mapping.

there: https://github.com/MovingBlocks/Terasology/blob/8840b62d8f3402db71c214225e82ffabe70b5e20/engine/src/main/java/org/terasology/persistence/serializers/NetworkEntitySerializer.java#L250-L253

There used idTable as mapping between Component's Type and id for networking. similar code used for Event's Types

It looks like desyncronization between client and server by ComponentType's ids. (may be we have some code, which add/remove component types, or not cleaned ids after previous game)