Competely Unexplainable Null Reference Exception - B21

Hi everyone, I’ve recently been testing my networked game that uses State Synchronisation to send each player’s position around the server and found that it hasn’t been working at all - as in all State Synchronisation on everything hasn’t been working - but all the RPC calls have been working.

A couple of days ago I was playing around in the editor and found a “Null Reference Exception” that had absolutely no stack trace. This error gets spammed into the console just after the first State Synchronisation update is received and so I began to ponder on whether that is the cause of the problem.

Please note that I’m using the Unity 5 beta, b21 to be precise.

If anyone has any form of explanation, it was be greatly appreciated.

Thanks

I haven’t yet reported this as a bug because the console only says “Null Reference Exception: Object reference not set to an instance of an object” and absolutely nothing else.

If you want proof that it says nothing but “Null Reference blah blah”, here it is:

Looks like that error happened 368 times. You should be able to highlight it and see a more detailed message below including the stack trace.

I did highlight it, as is shown at the bottom of the picture.

I’d turn off ‘Collapse’ in the Console window and check the very first error. Subsequent NullRefs are probably caused by an initial NullRef, possibly the Console window has collapsed multiple NullRefs from different call stacks together.

Unfortunately nothing changed: the error was still spammed into the console, I went through and highlighted each of them but there was still no stack trace to be found… This is so frustrating!

I decided to check what the error showed as in the output log for the build and this came up, this was the result:
(Filename: Line: -1)

NullReferenceException: Object reference not set to an instance of an object

I can’t see that being of any help but you never know.

Have you tried attaching the debugger and seeing where the exception is getting thrown?

1 Like

No, only because I have tons of different scripts running whilst I get the error

Wait. Debugger? I’m guessing you mean a Debug.Log call? If so how would that help me find the source when the null reference should tell me it?

No, I believe he means a debugger, like Visual Studio.

Oh, right. I’ll try it out and see whether it helps :slight_smile:

After some playing around, I have come to the conclusion that the error is coming from the NetworkView of the local player. The error only occurs when there are other players connected.

In MonoDevelop, under Run → Exceptions, select NullReferenceException and move it across. Then attach the debugger to Unity and when it throws the exception MonoDevelop should catch it and breakpoint.

1 Like

Okay, I’ve done as you said and the result backs up this theory:

What happened? You are likely asking. Well, the Null Reference occurred within Unity and Monodevelop un-minimised itself, as would be expected, then something weird happened: nothing changed. It stayed on the script that I had open prior to Monodevelop un-minimising itself, it didn’t jump to a new line or anything.

There must be something wrong with the local player’s networkview, but I’ve no idea what it could be!

I’ll keep looking and thanks for all your suggestions so far :slight_smile:

When MonoDevelop came up was the run button on the step bar (little red box in image) in the pause or play state?

Also, did the Call Stack window show anything (the big red box in image)?

Lastly, try ‘Run->Show Current Execution Line’ in MonoDevelop, if the run button is in the paused state (it would show the play arrow indicating that you are paused and need to press play to continue).

MonoDevelop was, indeed, paused. There was nothing in the Call Stack and when I clicked on “Show Current Execution Line” this happened:

(This also backs up my theory that there’s something wrong with the NetworkView.

Error while executing command: Show Current Execution Line

System.NullReferenceException: Object reference not set to an instance of an object.
at MonoDevelop.Debugger.DebuggingService.ShowCurrentExecutionLine() in c:\buildslave\monodevelop\build\monodevelop\main\src\addins\MonoDevelop.Debugger\MonoDevelop.Debugger\DebuggingService.cs:line 827
at MonoDevelop.Debugger.ShowCurrentExecutionLineCommand.Run() in c:\buildslave\monodevelop\build\monodevelop\main\src\addins\MonoDevelop.Debugger\MonoDevelop.Debugger\DebugCommands.cs:line 613
at MonoDevelop.Components.Commands.CommandHandler.Run(Object dataItem) in c:\buildslave\monodevelop\build\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Components.Commands\CommandHandler.cs:line 61
at MonoDevelop.Components.Commands.CommandHandler.InternalRun(Object dataItem) in c:\buildslave\monodevelop\build\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Components.Commands\CommandHandler.cs:line 42
at MonoDevelop.Components.Commands.CommandManager.DefaultDispatchCommand(ActionCommand cmd, CommandInfo info, Object dataItem, Object target, CommandSource source) in c:\buildslave\monodevelop\build\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Components.Commands\CommandManager.cs:line 1097
at MonoDevelop.Components.Commands.CommandManager.DispatchCommand(Object commandId, Object dataItem, Object initialTarget, CommandSource source) in c:\buildslave\monodevelop\build\monodevelop\main\src\core\MonoDevelop.Ide\MonoDevelop.Components.Commands\CommandManager.cs:line 1067

That’s a bummer. The last thing I would try is wrapping any usage of NetworkView in try…catch blocks and write out to Debug.Log in the catch.

I’ve done as you said but unfortunately I didn’t get anything because the only use of networkviews I actually reference in scripts are RPC calls which work perfectly fine :frowning:

Out of curiosity, is anyone else getting this? or is it just me?

I’ve just updated my project to Unity 5 (RC2) and I’m getting this problem as well in network games, with the very same lack of stack trace on the console, log, or MonoDevelop debugger. I’m going to see if I can reproduce it with a small test project, but I thought I’d ask first if you have any success narrowing does the cause @joeconstable97 ?

Unfortunately I haven’t been able to do so and have almost given up. I wish you luck with your search :slight_smile:

1 Like