fix: NetworkClient.Shutdown now clears OnDis/ConnectedEvents

This commit is contained in:
vis2k 2021-06-15 14:13:05 +08:00
parent 68a4a06926
commit e827c6c0f3
2 changed files with 19 additions and 0 deletions

View File

@ -1354,6 +1354,11 @@ public static void Shutdown()
if (Transport.activeTransport != null)
Transport.activeTransport.ClientDisconnect();
connection = null;
// clear events. someone might have hooked into them before, but
// we don't want to use those hooks after Shutdown anymore.
OnConnectedEvent = null;
OnDisconnectedEvent = null;
}
}
}

View File

@ -96,5 +96,19 @@ public void Send()
// received it on server?
Assert.That(called, Is.EqualTo(1));
}
[Test]
public void ShutdownCleanup()
{
// add some test event hooks to make sure they are cleaned up.
// there used to be a bug where they wouldn't be cleaned up.
NetworkClient.OnConnectedEvent = () => {};
NetworkClient.OnDisconnectedEvent = () => {};
NetworkClient.Shutdown();
Assert.That(NetworkClient.OnConnectedEvent, Is.Null);
Assert.That(NetworkClient.OnDisconnectedEvent, Is.Null);
}
}
}