Deciphering error message in a coroutine

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:

DETAILED EXCEPTION END

         System.NullReferenceException: Object reference not set to an instance of an object
PilotInterceptor+<SelectNewTarget>__6:MoveNext ()
 
(Filename:  Line: 538357416)

(That’s probably not the correct line number. :wink: )

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! :slight_smile:

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.

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.

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.

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.

I take it the next major release since March 2005 has fixed this? So, what does this stacktrace mean?

PilotInterceptor+c__Iterator9B.MoveNext ()

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.