Commit 0fc402a
committed
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.
Lethal Company v73 updated Unity Netcode for GameObjects (NGO) to
1.12.0, but the fix is available for NGO 1.14.0+ only.
References:
- https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/using-delegates
- Unity-Technologies/com.unity.netcode.gameobjects#3502
Fixes lc-sigurd#131 parent 33b273d commit 0fc402a
1 file changed
+73
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
54 | 92 | | |
55 | 93 | | |
56 | 94 | | |
| |||
65 | 103 | | |
66 | 104 | | |
67 | 105 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 106 | + | |
| 107 | + | |
79 | 108 | | |
80 | 109 | | |
81 | 110 | | |
| |||
98 | 127 | | |
99 | 128 | | |
100 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
101 | 161 | | |
102 | 162 | | |
103 | 163 | | |
104 | 164 | | |
105 | 165 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 166 | + | |
| 167 | + | |
111 | 168 | | |
112 | 169 | | |
113 | 170 | | |
| |||
0 commit comments