You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix delegates lifetime: unsubscribe stale handlers on network despawn
CSync leaves stale change handlers after quitting the hosted game.
When the host quits the game back to the main menu, ConfigSyncBehaviour
despawns and gets destroyed by Unity (not by .NET GC), but any delegates
connected to events in OnNetworkSpawn method remain and go stale.
So next time a player hosts a lobby without shutting down and
re-launching the game completely, when any of subscribed config files
or config entries change, stale delegates execute and try to assign to
a dead NetworkList _deltas[index]. Of course it results in an exception
being logged to the console by BepInEx (which wraps event handler
invocation in a try-catch).
To fix this, store subscribed delegates, and properly unsubscribe them
during despawn.
Note that NetworkList and _syncEnabled variable can not be cleared/reset
due to Unity issue which only got resolved in the most recent version.
References:
- https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/using-delegates
- Unity-Technologies/com.unity.netcode.gameobjects#3502Fixes#13
0 commit comments