Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

Obscure null reference exception without project context #2620

Closed powersupersport closed 1 year ago

powersupersport commented 1 year ago

I get this exception in some condition I can't fully isolate. Once this throws, it starts throwing every single update/tick. After throwing in play mode, it even starts throwing outside of play mode during layout repaint. There is no reference to any of my own scripts. Can someone from the developers take a look?

NullReferenceException: Object reference not set to an instance of an object
Unity.Netcode.FastBufferWriter.get_Length () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Serialization/FastBufferWriter.cs:69)
Unity.Netcode.MessagingSystem.ProcessSendQueues () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Messaging/MessagingSystem.cs:786)
Unity.Netcode.NetworkManager.OnNetworkPostLateUpdate () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Core/NetworkManager.cs:1488)
Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Core/NetworkManager.cs:1381)
Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Core/NetworkUpdateLoop.cs:185)
Unity.Netcode.NetworkUpdateLoop+NetworkPostLateUpdate+<>c.<CreateLoopSystem>b__0_0 () (at ./Library/PackageCache/com.unity.netcode.gameobjects@1.4.0/Runtime/Core/NetworkUpdateLoop.cs:268)

Reference from the last stack element: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/54666c3454a3a5468bca0e1575a0b3059653c64e/com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferWriter.cs#L69

I do not have experience with unsafe code, so I can't really reverse engineer the problem.

NoelStephensUnity commented 1 year ago

@powersupersport Could you provide the version of NGO and Unity Editor that you are using? It would help me determine what the issue might be.

powersupersport commented 1 year ago

@NoelStephensUnity Unity 2022.3.0, NGO 1.4.0

NoelStephensUnity commented 1 year ago

@powersupersport Ok, you might try to update to v1.5.1 and see if that resolves your issue. However, I don't think that is the issue at hand. Are you able to provide the series of steps you go through to get this issue to happen? Example: I have a single scene that contains a GameObject with a NetworkManager component and (additional information about any NGO/Netcode specific instances like in-scene placed NetworkObjects etc).

If not, then if you are able to provide an example project in zip form (including only the Assets and Packages folders) that would help. If not, then could you file a bug through the Unity Editor (i.e. Help-->Report a bug), include your project in the bug report (so I can take a look and see why that is happening), and once you have filed the report you should receive an email with bug ticket number that I would need you to post here so I can get that bug forwarded to our bug database.

powersupersport commented 1 year ago

Are you able to provide the series of steps you go through to get this issue to happen?

I wish I could. I would've honestly tried to solve the problem on my own if it was consistent.

It rarely happens if I connect a client to the server, load a scene, then quickly disconnect them. Though none of that info is very helpful at all.

I am not sure if I can even reproduce the issue in a fresh project, as again, if I could I would've probably resolved it.

With all respect, I do not wish to send my entire project to Unity, especially using the bug reporter (sends a lot of unnecessary data about my running processes). If you can't assist me further that's totally fine. Thank you for your time.

you might try to update to v1.5.1

I will try doing that and monitor if it fixes it.

powersupersport commented 1 year ago

@NoelStephensUnity

Since updating to v1.5.1 the issue doesn't seem to appear anymore. I haven't done anything too different, so I still can't confirm what was the exact cause. I'll make sure to reopen if the issue appears again.