Skip to content

Commit ab4234e

Browse files
fix: stop a discarded UnifiedBootstrap from clearing the world being created
Every NetworkManager that starts a hybrid session creates a UnifiedBootstrap that is then discarded, and its finalizer cleared the static LastCreatedWorld and Instance from the GC finalizer thread. When one ran while another session was starting, Initialize found its new world null, logged "World is null!" and returned false: the NetworkManager had no world, its transport threw a NullReferenceException on start, and the created world was never disposed. The finalizer is removed and Initialize checks the world it created rather than the static.
1 parent a49ad61 commit ab4234e

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

‎com.unity.netcode.gameobjects/Runtime/Components/Helpers/UnifiedBootstrap.cs‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ public override bool Initialize(string defaultWorldName)
7171
RegisterCreatedWorlds();
7272
Debug.Log($"Starting a world for {(networkManager.IsServer ? "Host" : "Client")}");
7373
s_WorldCounter++;
74-
LastCreatedWorld = CreateWorld(networkManager);
74+
var world = CreateWorld(networkManager);
75+
LastCreatedWorld = world;
7576

76-
if (LastCreatedWorld == null)
77+
if (world == null)
7778
{
7879
s_WorldCounter--;
7980
Debug.LogError($"[{nameof(UnifiedBootstrap)}] World is null!");
8081
return false;
8182
}
8283

83-
if (!LastCreatedWorld.IsCreated)
84+
if (!world.IsCreated)
8485
{
8586
s_WorldCounter--;
8687
Debug.LogError($"[{nameof(UnifiedBootstrap)}] World was not created!");
@@ -89,10 +90,10 @@ public override bool Initialize(string defaultWorldName)
8990

9091
if (networkManager.LogLevel <= LogLevel.Developer)
9192
{
92-
NetworkLog.LogInfo($"[{nameof(UnifiedBootstrap)}] Created world: {LastCreatedWorld.Name} / {LastCreatedWorld.SequenceNumber}");
93+
NetworkLog.LogInfo($"[{nameof(UnifiedBootstrap)}] Created world: {world.Name} / {world.SequenceNumber}");
9394
}
9495

95-
networkManager.NetcodeWorld = (NetcodeWorld)LastCreatedWorld;
96+
networkManager.NetcodeWorld = (NetcodeWorld)world;
9697
s_CreatedWorlds.Add(networkManager.NetcodeWorld);
9798
}
9899
else
@@ -132,12 +133,6 @@ private static World CreateWorld(NetworkManager networkManager)
132133
return networkManager.IsServer ? CreateSingleWorldHost($"HostSingleWorld-{s_WorldCounter}") : CreateClientWorld($"ClientWorld-{s_WorldCounter}");
133134
#endif
134135
}
135-
136-
~UnifiedBootstrap()
137-
{
138-
LastCreatedWorld = null;
139-
Instance = null;
140-
}
141136
}
142137
}
143138
#endif

0 commit comments

Comments
 (0)