mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: NetworkServer.BroadcastToConnectio can now recover from null entries instead of slowing down perf with log messages forever [credits: BigBoxVR/CF]
This commit is contained in:
parent
0cb777d3dd
commit
c77d8459fb
@ -1870,6 +1870,7 @@ static NetworkWriter SerializeForConnection(NetworkIdentity identity, NetworkCon
|
|||||||
static void BroadcastToConnection(NetworkConnectionToClient connection)
|
static void BroadcastToConnection(NetworkConnectionToClient connection)
|
||||||
{
|
{
|
||||||
// for each entity that this connection is seeing
|
// for each entity that this connection is seeing
|
||||||
|
bool hasNull = false;
|
||||||
foreach (NetworkIdentity identity in connection.observing)
|
foreach (NetworkIdentity identity in connection.observing)
|
||||||
{
|
{
|
||||||
// make sure it's not null or destroyed.
|
// make sure it's not null or destroyed.
|
||||||
@ -1895,8 +1896,16 @@ static void BroadcastToConnection(NetworkConnectionToClient connection)
|
|||||||
// always call Remove in OnObjectDestroy everywhere.
|
// always call Remove in OnObjectDestroy everywhere.
|
||||||
// if it does have null then someone used
|
// if it does have null then someone used
|
||||||
// GameObject.Destroy instead of NetworkServer.Destroy.
|
// GameObject.Destroy instead of NetworkServer.Destroy.
|
||||||
else Debug.LogWarning($"Found 'null' entry in observing list for connectionId={connection.connectionId}. Please call NetworkServer.Destroy to destroy networked objects. Don't use GameObject.Destroy.");
|
else
|
||||||
|
{
|
||||||
|
hasNull = true;
|
||||||
|
Debug.LogWarning($"Found 'null' entry in observing list for connectionId={connection.connectionId}. Please call NetworkServer.Destroy to destroy networked objects. Don't use GameObject.Destroy.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recover from null entries.
|
||||||
|
// otherwise every broadcast will spam the warning and slow down performance until restart.
|
||||||
|
if (hasNull) connection.observing.RemoveWhere(identity => identity == null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to check a connection for inactivity and disconnect if necessary
|
// helper function to check a connection for inactivity and disconnect if necessary
|
||||||
|
Loading…
Reference in New Issue
Block a user