Skip to content

CSync leaves stale change handlers after quitting the hosted game #13

@ratijas

Description

@ratijas

CSync leaves stale change handlers after quitting the hosted game

When the host quits the game back to the main menu, events handlers from ConfigSyncBehaviour.OnNetworkSpawn -> ConfigFile.SettingChanged somehow become stale such that its assignment _deltas[currentIndex] = syncedEntryBase.ToDelta(); causes NullReferenceException:

[Error  :   BepInEx] System.NullReferenceException: Object reference not set to an instance of an object
  at Unity.Collections.LowLevel.Unsafe.UnsafeList`1[T].get_Item (System.Int32 index) [0x00000] in <d0c0081e1ce74649912b55aa702cd13d>:0
  at Unity.Collections.NativeList`1[T].get_Item (System.Int32 index) [0x00000] in <d0c0081e1ce74649912b55aa702cd13d>:0
  at Unity.Netcode.NetworkList`1[T].set_Item (System.Int32 index, T value) [0x00023] in <895801699cfc4b4ab52267f31e2a4998>:0
  at CSync.Lib.ConfigSyncBehaviour+<>c__DisplayClass18_0.<OnNetworkSpawn>b__0 (System.Object _, BepInEx.Configuration.SettingChangedEventArgs args) [0x00014] in /home/runner/work/CSync/CSync/CSync/CSync/Lib/ConfigSyncBehaviour.cs:70
  at BepInEx.Configuration.ConfigFile.OnSettingChanged (System.Object sender, BepInEx.Configuration.ConfigEntryBase changedEntryBase) [0x00048] in <fe49c90fe8e24102b42489c11910c71c>:0

Every time the host quick the game, one more set of handlers become stale, so after 2nd quick there are two exceptions per value change, after 3rd quick there are three at once and so on.

It doesn't happen for clients unless they tried to host too. If a player previously hosted, quit, and joined as a client, then syncing a value from host would behave alright, but trying to change the value locally would result in the following InvalidOperationException:

[Error  :   BepInEx] System.InvalidOperationException: Client is not allowed to write to this NetworkList
  at Unity.Netcode.NetworkList`1[T].set_Item (System.Int32 index, T value) [0x00018] in <895801699cfc4b4ab52267f31e2a4998>:0
  at CSync.Lib.ConfigSyncBehaviour+<>c__DisplayClass18_1.<OnNetworkSpawn>b__0 (System.Object _, BepInEx.Configuration.SettingChangedEventArgs args) [0x00022] in D:\Code\CSync\CSync\CSync\Lib\ConfigSyncBehaviour.cs:70
  at BepInEx.Configuration.ConfigFile.OnSettingChanged (System.Object sender, BepInEx.Configuration.ConfigEntryBase changedEntryBase) [0x00048] in <fe49c90fe8e24102b42489c11910c71c>:0

AFAICT it does not affect the ability of CSync to synchronize the actual values. (Although yesterday I got a desync somehow, which prompted this investigation in the first place).

This bug happens even with the provided ExamplePlugin. The only way to fix is to close the game completely and launch again.

I use LethalConfig v1.4.6 by AinaVT to change values via in-game UI, and LCDirectLAN v1.1.3 by TIRTAGT to test between two devices on my local network.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions