Skip to content

Commit e07450f

Browse files
fix: Correctly dispose of everything in adapter's OnDestroy (#1640)
* Correctly dispose of everything in OnDestroy * Add CHANGELOG entry Co-authored-by: Noel Stephens <noel.stephens@unity3d.com>
1 parent ef257a9 commit e07450f

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

com.unity.netcode.adapter.utp/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All notable changes to this package will be documented in this file. The format
1313
### Fixed
1414

1515
- Fixed issue where the server `NetworkEndPoint` would fail to be created when 'Server Listen Address' is empty. (#1636)
16+
- Fixed issue with native collections not all being disposed of when destroying the component without shutting it down properly. This would result in errors in the console and memory leaks. (#1640)
1617

1718
## [1.0.0-pre.5] - 2022-01-26
1819

com.unity.netcode.adapter.utp/Runtime/UnityTransport.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,21 @@ private void InitDriver()
241241
out m_ReliableSequencedPipeline);
242242
}
243243

244-
private void DisposeDriver()
244+
private void DisposeInternals()
245245
{
246246
if (m_Driver.IsCreated)
247247
{
248248
m_Driver.Dispose();
249249
}
250+
251+
m_NetworkSettings.Dispose();
252+
253+
foreach (var queue in m_SendQueue.Values)
254+
{
255+
queue.Dispose();
256+
}
257+
258+
m_SendQueue.Clear();
250259
}
251260

252261
private NetworkPipeline SelectSendPipeline(NetworkDelivery delivery)
@@ -662,7 +671,7 @@ private void Update()
662671

663672
private void OnDestroy()
664673
{
665-
DisposeDriver();
674+
DisposeInternals();
666675
}
667676

668677
#if MULTIPLAYER_TOOLS
@@ -870,23 +879,12 @@ public override void Shutdown()
870879
return;
871880
}
872881

873-
874882
// Flush the driver's internal send queue. If we're shutting down because the
875883
// NetworkManager is shutting down, it probably has disconnected some peer(s)
876884
// in the process and we want to get these disconnect messages on the wire.
877885
m_Driver.ScheduleFlushSend(default).Complete();
878886

879-
DisposeDriver();
880-
881-
m_NetworkSettings.Dispose();
882-
883-
foreach (var queue in m_SendQueue.Values)
884-
{
885-
queue.Dispose();
886-
}
887-
888-
// make sure we don't leak queues when we shutdown
889-
m_SendQueue.Clear();
887+
DisposeInternals();
890888

891889
// We must reset this to zero because UTP actually re-uses clientIds if there is a clean disconnect
892890
m_ServerClientId = 0;

0 commit comments

Comments
 (0)