Skip to content

Commit 6899764

Browse files
committed
Added more Buffer/Synchronization safety changes
Prevents instantiation data synchronization failures from propagating, ensuring that exceptions thrown during synchronization are caught and logged, and that resources are properly released. This change improves the robustness of the instantiation process.
1 parent 426d82c commit 6899764

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,10 +1861,18 @@ internal void InjectInstantiationData()
18611861
{
18621862
if (NetworkManager.PrefabHandler.TryGetHandlerWithData(this.GlobalObjectIdHash, out var prefabHandler))
18631863
{
1864-
// Creates the instantiateData array for the newtwork object
18651864
var serializer = new BufferSerializer<BufferSerializerWriter>(new BufferSerializerWriter(new FastBufferWriter(4, Collections.Allocator.Temp, int.MaxValue)));
1866-
prefabHandler.OnSynchronizeInstantiationData(ref serializer);
1867-
InstantiationData = serializer.GetFastBufferWriter().ToArray();
1865+
try
1866+
{
1867+
prefabHandler.OnSynchronizeInstantiationData(ref serializer);
1868+
InstantiationData = serializer.GetFastBufferWriter().ToArray();
1869+
}
1870+
catch (Exception ex)
1871+
{
1872+
serializer.GetFastBufferWriter().Dispose();
1873+
NetworkLog.LogError($"[InstantiationData] Handler failed during synchronization for injection (Write): {ex.Message}");
1874+
return;
1875+
}
18681876
}
18691877
}
18701878

0 commit comments

Comments
 (0)