mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: NetworkClient.Disconnect avoids NullReferenceException if Transport ClientDisconnect calls OnDisconnected immediately. Related to: https://github.com/vis2k/Mirror/issues/2353
This commit is contained in:
parent
ebc9f7a4b3
commit
85be663b13
@ -128,7 +128,14 @@ public static void Disconnect()
|
||||
if (connection != null)
|
||||
{
|
||||
connection.Disconnect();
|
||||
connection.Dispose();
|
||||
// connection.Disconnect calls Transport.ClientDisconnect.
|
||||
// if transport calls Mirror's OnDisconnected event immediately
|
||||
// before returning, then we end up in a circular call:
|
||||
// https://github.com/vis2k/Mirror/issues/2353
|
||||
// in which case connection becomes null after returning here.
|
||||
// in other words, the following Dispose call needs to use '.?'
|
||||
// to avoid NullReferenceExceptions.
|
||||
connection?.Dispose();
|
||||
connection = null;
|
||||
RemoveTransportHandlers();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user