Skip to content

Commit 400a2be

Browse files
fix: RpcQueueContainer deregister from NetworkUpdateManager (#453)
* fix: deregistration fix This fixes the issue with the RpcQueueContainer not deregistering itself from the NetworkUpdateManager upon shutdown of the NetworkingManager. * refactor: Removing comment Removing a comment that doesn't need to be there. * refactor: code clarity @jeffreyrainy suggested that the OnExiting method was confusing and it didn't make sense having more than one method to call in order to handle cleaning up and deregistering from the network update loop. These changes refactors the method used to handle shutting down.
1 parent d11088c commit 400a2be

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

com.unity.multiplayer.mlapi/Runtime/Core/NetworkingManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ private void OnDestroy()
670670
{
671671
OnNetworkLoopSystemRemove();
672672
//NSS: This is ok to leave this check here
673-
rpcQueueContainer?.OnExiting();
673+
rpcQueueContainer?.Shutdown();
674674

675675
if (Singleton != null && Singleton == this)
676676
{
@@ -693,7 +693,8 @@ private void Shutdown()
693693
SpawnManager.DestroyNonSceneObjects();
694694
SpawnManager.ServerResetShudownStateForSceneObjects();
695695

696-
if (NetworkConfig != null && NetworkConfig.NetworkTransport != null) //The Transport is set during Init time, thus it is possible for the Transport to be null
696+
//The Transport is set during Init time, thus it is possible for the Transport to be null
697+
if (NetworkConfig != null && NetworkConfig.NetworkTransport != null)
697698
NetworkConfig.NetworkTransport.Shutdown();
698699

699700
if (rpcQueueContainer != null)

com.unity.multiplayer.mlapi/Runtime/Messaging/RPCQueue/RPCQueueContainer.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,9 @@ public bool IsTesting()
649649
return m_IsTestingEnabled;
650650
}
651651

652+
652653
/// <summary>
653-
/// Clears all declared parameters
654+
/// Clears the stream indices and frames process properties
654655
/// </summary>
655656
private void ClearParameters()
656657
{
@@ -661,10 +662,12 @@ private void ClearParameters()
661662
}
662663

663664
/// <summary>
664-
/// OnExiting
665-
/// Called upon exiting to assure any last messages are delivered.
665+
/// Shutdown
666+
/// Flushes the internal messages
667+
/// Removes itself from the network update loop
668+
/// Disposes readers, writers, clears the queue history, and resets any parameters
666669
/// </summary>
667-
public void OnExiting()
670+
public void Shutdown()
668671
{
669672
//We need to make sure all internal messages (i.e. object destroy) are sent
670673
rpcQueueProcessing.InternalMessagesSendAndFlush();
@@ -675,14 +678,8 @@ public void OnExiting()
675678
//Remove ourself from the network loop update system
676679
OnNetworkLoopSystemRemove();
677680
}
678-
}
679681

680-
/// <summary>
681-
/// There might be a case where we want to make this class non-static and in that case we would replace this with Dispose and add the IDisposable interface
682-
/// For now, this should be called upon shutdown
683-
/// </summary>
684-
public void Shutdown()
685-
{
682+
//Dispose of any readers and writers
686683
foreach (KeyValuePair<QueueHistoryFrame.QueueFrameType, Dictionary<int, Dictionary<NetworkUpdateManager.NetworkUpdateStages, QueueHistoryFrame>>> queueHistorySection in QueueHistory)
687684
{
688685
foreach (KeyValuePair<int, Dictionary<NetworkUpdateManager.NetworkUpdateStages, QueueHistoryFrame>> queueHistoryItemByStage in queueHistorySection.Value)
@@ -696,6 +693,7 @@ public void Shutdown()
696693
}
697694
}
698695

696+
//Clear history and parameters
699697
QueueHistory.Clear();
700698

701699
ClearParameters();

0 commit comments

Comments
 (0)