Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

[bug] IsNetworkInitialized breaks if checked before _net set #76

Closed sayangel closed 6 years ago

sayangel commented 6 years ago

Context

Checking IsNetworkInitialized before _net has been set by the Start() function results in error. I am calling it from a listener on Rooms.JoinedRoom, but Dissonance doesn't seem to be fully initialized.

Expected Behavior

If _net is not set IsNetworkInitialized should return false.

Actual Behavior

NullReferenceException: Object reference not set to an instance of an object
Dissonance.DissonanceComms.get_IsNetworkInitialized () (at Assets/Plugins/Dissonance/DissonanceComms.cs:198)

Workaround

Check IsNetworkInitialized on the next frame to ensure existence of _net in Dissonance instance.

Fix

Current Code:

      public bool IsNetworkInitialized
        {
            get { return _net.Status == ConnectionStatus.Connected; }
        }

Fix:

      public bool IsNetworkInitialized
        {
            get { return _net != null && _net.Status == ConnectionStatus.Connected; }
        }
martindevans commented 6 years ago

Hi sayangel, thanks for the excellent bug report :+1:

Your workaround is exactly right. I've also added checks to VoiceBroadcastTrigger and VoiceReceiptTrigger so that they will not do anything until DissonanceComms:Start has been called, to make things a bit neater in the most common path. That should be included in the next version of Dissonance.

martindevans commented 6 years ago

Dissonance 6.1.0 just released onto the asset store with a fix for this. I'll close the issue but please don't hesitate to re-open it if it's still a problem :)