Search Unity

Deciphering error message in a coroutine

Discussion in 'Scripting' started by NCarter, Apr 14, 2006.

  1. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    I'm getting an infrequent null reference exception in one of my coroutines. I'm sure I can figure out where the problem lies myself after a bit of testing, but I have a question about the error message which results from this crash:

    Code (csharp):
    1. DETAILED EXCEPTION END
    2.  
    3.          System.NullReferenceException: Object reference not set to an instance of an object
    4. PilotInterceptor+<SelectNewTarget>__6:MoveNext ()
    5.  
    6. (Filename:  Line: 538357416)
    (That's probably not the correct line number. ;) )

    I'm wondering how I should interpret the above message. PilotInterceptor is the name of the class and SelectNewTarget is the coroutine, but what does the __6 and MoveNext refer to? The latter is presumably an internal Unity symbol since it doesn't appear in my code. It there any useful information that can be extracted from this?

    Any clues would be appreciated! :)
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    It says that it happens in the script PilotInterceptor and it's function SelectNewTarget.

    This is just a bug where stacktraces for coroutines aren't generated correctly.
    One way to get to the exact stacktrace is to call another function from the coroutine.


    And yes, we are fixing stacktraces to always report the exact line number with the next major release. Also we will include a lot of information about why exactly you got that null reference exception.


    You should not be able to crash the editor though, if you can, please report a bug.
     
  3. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    That's good to know, thanks.

    No, it was just my code causing Mono to crash. I found my mistake a few seconds after I posted - I forgot to check if my target finding method was returning null when nothing was in range.

    Thanks for the hint about calling another method to get a better stack trace, that's very helpful.
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You should not be able to crash the Unity editor. Even if you dereference a null pointer.

    Btw. are you sure unity actually crashed. Sometimes the apple crash reporter pops up but unity has actually not crashed.
     
  5. NCarter

    NCarter

    Joined:
    Sep 3, 2005
    Posts:
    686
    Yes, that's what I meant. It was just a crash in my script (which caused the Apple crash reporter to appear), and Unity continued to work without problems.
     
  6. TamaHobbit

    TamaHobbit

    Joined:
    May 18, 2014
    Posts:
    10
    I take it the next major release since March 2005 has fixed this? So, what does this stacktrace mean?

    PilotInterceptor+c__Iterator9B.MoveNext ()
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Holy mother of necro post.

    The stacktrace means that the error happens in the IEnumerator's MoveNext method. It should also include the line number that shows where inside your IEnumerator the error is thrown.

    A lot of stuff happens with a coroutine, but in essence, the IEnumerator you define in your method is generated, and MoveNext is called on it every Update until it's done. So your coroutine is throwing an error during that.