Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

[bug] MissingReferenceException in NfgoPlayer.cs when disconnecting from Unity NGO host server #276

Closed Thendon closed 1 year ago

Thendon commented 1 year ago

Context

When disconnecting from server (only tested in host situation though) I got this error every frame.

(Filename: Assets/Thirdparty/Dissonance/Integrations/Unity_NFGO/NfgoPlayer.cs Line: 22)

MissingReferenceException: The object of type 'NfgoPlayer' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
  at (wrapper managed-to-native) UnityEngine.Component.get_transform(UnityEngine.Component)
  at Dissonance.Integrations.Unity_NFGO.NfgoPlayer.get_Transform () [0x0000e] in C:\Working\Unity Projects\rtvr-unity_clone_0\Assets\Thirdparty\Dissonance\Integrations\Unity_NFGO\NfgoPlayer.cs:22 
  at Dissonance.Integrations.Unity_NFGO.NfgoPlayer.get_Position () [0x00000] in C:\Working\Unity Projects\rtvr-unity_clone_0\Assets\Thirdparty\Dissonance\Integrations\Unity_NFGO\NfgoPlayer.cs:27 
  at Dissonance.RemoteVoicePlayerState.Update () [0x0001f] in C:\Working\Unity Projects\rtvr-unity_clone_0\Assets\Plugins\Dissonance\Core\VoicePlayerState.cs:521 
  at Dissonance.PlayerCollection.Update () [0x00004] in C:\Working\Unity Projects\rtvr-unity_clone_0\Assets\Plugins\Dissonance\Core\PlayerCollection.cs:87 
  at Dissonance.DissonanceComms.Update () [0x00050] in C:\Working\Unity Projects\rtvr-unity_clone_0\Assets\Plugins\Dissonance\Core\DissonanceCommsImpl.cs:679 

Workaround / Fix

For now I just added a StopTracking method into the OnDestroy hook of the NfgoPlayer.cs class. It looks like this now.

        public override void OnDestroy()
        {
            if (IsTracking)
                StopTracking();
            if (_comms != null)
                _comms.LocalPlayerNameChanged -= OnLocalPlayerIdChanged;
            _playerId.OnValueChanged -= OnNetworkVariablePlayerIdChanged;
        }

Your Environment

Include as many relevant details about the environment you experienced the bug in

martindevans commented 1 year ago

Thanks for the report and the workaround. I'll look into adding that into OnDestroy in the main package.

martindevans commented 1 year ago

This has been added to the main package as is available on the asset store (v9.0.2). Thanks again for reporting this.