BoltEngine / Bolt-Tracker

New issue tracker for Photon Bolt
10 stars 2 forks source link

BoltNetwork.get_IsSinglePlayer () gives NullReferenceException after Bolt Shutdown #163

Closed paulo-lafeta closed 3 years ago

paulo-lafeta commented 4 years ago

Describe the bug Call to BoltNetwork.IsSinglePlayer is giving NullReferenceException after Photon Bolt is disconnected.

"NullReferenceException: Object reference not set to an instance of an object BoltNetwork.get_IsSinglePlayer ()"

This happens even though BoltNetwork.IsRunning returns as true.

To Reproduce Steps to reproduce the behavior:

  1. Connect to Photon Bolt normally.
  2. Shutdown Bolt with BoltNetwork.Shutdown();
  3. Try to call BoltNetwork.IsSinglePlayer function.
  4. See NullReferenceException occur.

PS: BoltNetwork.IsRunning doesn't give NullRef after Bolt Shutdown.

Expected behavior No NullReferenceException when calling BoltNetwork.IsSinglePlayer function.

Actual behavior NullReferenceException when calling BoltNetwork.IsSinglePlayer function after Bolt Shutdown.

Desktop:

Additional context

ramonmelo commented 4 years ago

Hello @paulo-lafeta ,

I'm not entirely sure where or when you are checking the BoltNetwork.IsSinglePlayer, but I do not found any issue when running some tests based on your description. Maybe you can clarify with a reproduction sample? Which Bolt version are you using?

Here is the sample code I'm using the check your issue: single_player_null_issue.unitypackage.zip.

You will find in the zip a script that lets you start Bolt as a Server or in Single Player mode, and after it's running, you can call the Shutdown. On the BoltShutdownBegin callback, it's verified if Bolt is running and then check if it was running as Single Player. This step occurs before and after Bolt completes its shutdown procedure.

Before the shutdown completes, Bolt is still running, so it will log the BoltNetwork.IsSinglePlayer, after the shutdown, it will simply log Bolt is not Running.

tkgszaluga commented 3 years ago

Hi Ramon,

I am seeing this error as well. Looks like the shutdown is asynchronous and at some point some UdpSocket becomes null, even though Bolt's IsRunning property still reports true. I am able to reproduce it fairly easily with our debug gui. We're printing something like this from withinOnGui() (every frame): GUILayout.Label($"IsSinglePlayer: {BoltNetwork.IsRunning && BoltNetwork.IsSinglePlayer}"); If Bolt is connected and I call Shutdown(), after a couple of frames I will start getting exceptions. A workaround for this is: GUILayout.Label($"IsSinglePlayer: {BoltNetwork.IsRunning && BoltNetwork.UdpSocket != null && BoltNetwork.IsSinglePlayer}");

ramonmelo commented 3 years ago

Hello @tkgszaluga ,

Interesting, we will take a look. Thanks for your feedback.

-- Ramon Melo Photon Bolt Team

ramonmelo commented 3 years ago

Thanks for your feedback,

Fixed on the next release.

The workaround from @tkgszaluga would work fine for now.