Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Competely Unexplainable Null Reference Exception - B21

Discussion in 'Unity 5 Pre-order Beta' started by joeconstable97, Jan 29, 2015.

  1. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    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:
     

    Attached Files:

    • yep.png
      yep.png
      File size:
      10.9 KB
      Views:
      1,236
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    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.
     
  3. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    I did highlight it, as is shown at the bottom of the picture.
     
  4. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    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.
     
  5. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    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!
     
    Last edited: Jan 30, 2015
  6. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    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.
     
  7. tango209

    tango209

    Joined:
    Feb 23, 2011
    Posts:
    379
    Have you tried attaching the debugger and seeing where the exception is getting thrown?
     
    Dustin-Horne likes this.
  8. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    No, only because I have tons of different scripts running whilst I get the error
     
  9. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    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?
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    No, I believe he means a debugger, like Visual Studio.
     
  11. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    Oh, right. I'll try it out and see whether it helps :)
     
  12. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    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.
     
    Last edited: Jan 30, 2015
  13. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    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.
     
    andymads likes this.
  14. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    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 :)
     
  15. tango209

    tango209

    Joined:
    Feb 23, 2011
    Posts:
    379
    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).

    debug.png
     
  16. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    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
     
  17. tango209

    tango209

    Joined:
    Feb 23, 2011
    Posts:
    379
    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.
     
  18. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    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 :(

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

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    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 @iiTZJOEY?
     
  20. joeconstable97

    joeconstable97

    Joined:
    Jul 30, 2013
    Posts:
    50
    Unfortunately I haven't been able to do so and have almost given up. I wish you luck with your search :)
     
    JJC1138 likes this.
  21. JJC1138

    JJC1138

    Joined:
    Feb 23, 2012
    Posts:
    89
    I think I've tracked this down. It turns out that it happens whenever you try to use a NetworkView to synchronize a MonoBehaviour with a custom OnSerializeNetworkView() method. If you leave off the NetworkMessageInfo argument then you get a null BitStream, which was reported elsewhere by @GibTreaty. But when you do have the NetworkMessageInfo argument, though, you get the NullReferenceException with no stack trace that you and I are seeing.
     
    GibTreaty likes this.
  22. HugoZandel

    HugoZandel

    Joined:
    Mar 11, 2014
    Posts:
    52
    I'm experiencing the same issue