Skip to content

Commit

Permalink
fix: Bug with NI destroy order (#374)
Browse files Browse the repository at this point in the history
* failing test

* fix for failing test. dont destroy self until end
  • Loading branch information
uweeby committed Oct 2, 2020
1 parent 49a16dd commit 485f78b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Assets/Mirror/Runtime/NetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,16 @@ public void DestroyOwnedObjects()
var tmp = new HashSet<NetworkIdentity>(clientOwnedObjects);
foreach (NetworkIdentity netIdentity in tmp)
{
if (netIdentity != null)
//dont destroy self yet.
if (netIdentity != null && netIdentity != Identity)
{
Identity.Server.Destroy(netIdentity.gameObject);
}
}

// Destroy the connections own identity.
Identity.Server.Destroy(Identity.gameObject);

// clear the hashset because we destroyed them all
clientOwnedObjects.Clear();
}
Expand Down
17 changes: 17 additions & 0 deletions Assets/Tests/Runtime/NetworkIdentityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,22 @@ public void IdentityServerValueSet()
{
Assert.That(identity.Server, Is.Not.Null);
}

[UnityTest]
public IEnumerator DestroyOwnedObjectsTest() => RunAsync(async () =>
{
GameObject testObj1 = new GameObject();
GameObject testObj2 = new GameObject();
GameObject testObj3 = new GameObject();
server.LocalConnection.AddOwnedObject(testObj1.AddComponent<NetworkIdentity>());
server.LocalConnection.AddOwnedObject(testObj2.AddComponent<NetworkIdentity>());
server.LocalConnection.AddOwnedObject(testObj3.AddComponent<NetworkIdentity>());
server.LocalConnection.DestroyOwnedObjects();
await WaitFor(() => !testObj1);
await WaitFor(() => !testObj2);
await WaitFor(() => !testObj3);
});
}
}

0 comments on commit 485f78b

Please sign in to comment.