Skip to content

fix: destroy object spam #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 23, 2021
Merged

fix: destroy object spam #651

merged 2 commits into from
Mar 23, 2021

Conversation

NoelStephensUnity
Copy link
Collaborator

This fixes an issue where the destroy method can get called twice on the client side after receiving a destroy object command.

This fix is pertaining to MTT-556
This is a temporary fix until the spawning and de-spawning process has been fully vetted.
This fix prevents the MonoBehavior.OnDestroy method from invoking the NetworkSpawnManager.OnDestroyObject method if it does not exist in the NetworkSpawnManager.SpawnedObjects list.

This fixes an issue where the destroy method can get called twice on the client side after receiving a destroy object command.
@@ -361,7 +361,7 @@ public static void NetworkHide(List<NetworkObject> networkObjects, ulong clientI

private void OnDestroy()
{
if (NetworkManager.Singleton != null)
if (NetworkManager.Singleton != null && NetworkSpawnManager.SpawnedObjects.Count > 0 && NetworkSpawnManager.SpawnedObjects.ContainsKey(NetworkObjectId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count > 0 check shouldn't be necessary as it is always true if ContainsKey returns true right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking an Int value first is faster than checking a hashed set, so it is just an early out optimization. Not required.
Of course, if it is > then you have the int compare plus the hashed set check... :/

50/50 on this.. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went ahead and removed it in 5e04e7e.

Copy link
Contributor

@LukeStampfli LukeStampfli Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah I see I guess yours is much faster. I hoped dictionary would make an empty check with contains key but apparently after checking the source it doesn't.

Decided this isn't worth the optimization.
@mattwalsh-unity mattwalsh-unity merged commit 5a5fc05 into develop Mar 23, 2021
@mattwalsh-unity mattwalsh-unity deleted the fix/destroyobjectspam branch March 23, 2021 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants