Fix GameObjects in GameObjectSystem NetLists being null on clients #106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix GameObjects in GameObjectSystem NetLists / NetDictionaries being null on clients.
Issue: Facepunch/sbox-issues#9694
Changes
SceneNetworkSystem.cs:
GameObjectSystemdata table reading to afterGameObjectspawningScene.Network.cs:
isDirtyflags are cleared every network updateNotes
When
GameObjectSystemdata tables were read beforeGameObjectsspawned,GameObjectsinNetList/NetDictionarieswerenullbecause lookup byGUIDfailed.There was a second issue that meant that the first client to connect would not experience the first bug. When the
NetListis changed on the host, it's entry within theNetworkTableis marked asisDirty. This is only ever toggled when a network update is sent. Since there are no connections at first, no network update is sent and soisDirtyremains true until the first client connects.When the first client connects, it encounters the first bug, but immediately after it receives an additional delta snapshot which fixes it. This then toggles
isDirtytofalsefor that entry on the server, so every other client that connects now develops the first bug with no correction snapshot afterwards.I found this really confusing. It took me ages to understand why the first client was being treated differently from all the rest. I think the code should be changed so that even when no clients are connected
isDirtywill still be set tofalsewhen theSceneNetworkUpdateticks. This way, every client will run the same code regardless of if they are the first to connect to the server or not. The change I made toScene.Network.csdoes this. I don't think it will have a big performance impact because when there are no changes it just returns early. It might not affect anything else outside of the first bug but I still think it's better to not have some clients running different code from the rest. It could end up masking other bugs that you wouldn't notice while testing if you only connected with one client.If you want to avoid the extra work when there are no clients connected, other than the host, it should be done in another way, so that
isDirtyis still set tofalseeachSceneNetworkUpdateregardless of whether an update was sent to anyone or not.