Public Coroutine == Crash

Issue #200 resolved
Steamroller Studios created an issue

We have been experiencing crashes with Unity recently. We think we have tracked the problem down to a script that had a Coroutine field marked as a "public". Anytime we would mess with a prefab that had that script attached, then hit play... Crash.

Since making the Coroutine variable private, this issue has gone away. I know there is no good reason for having a Coroutine property being public, but it was and it was crashing.

I should also mention, this class was inheriting directly from MonoBehaviour and not SerializedBehaviour and that we started getting these crashes after migrating over to Odin.

This isn't a huge issue since the work-around is there, but thought you guys should know what we think we found.

Comments (3)

  1. Tor Esa Vestergaard
    • changed status to open

    Thanks for the heads-up; I'll take a look at this and see if I can find out what might be causing that.

  2. Tor Esa Vestergaard

    Luckily this was both easy to reproduce and easy to "fix". This turned out to be yet another special case in Unity where we need a bit of extra special case code here and there to make sure things don't break. Odin was generating a "default" instance of a Coroutine when it was being inspected, since it incorrectly guessed that this was a regular type that Unity would serialize. This would usually be harmless, but Coroutines are apparently dangerous things.

    The actual crash itself happens whenever a Coroutine with an invalid internal pointer (such as a zero pointer) is garbage collected. This code, in fact, is enough to cause the crash instantly:

    var routine = Activator.CreateInstance(typeof(Coroutine), true);
    routine = null;

    This issue is now resolved, and the fix will be in the next patch :) Once again, thanks for the heads up, and sorry for the headache it must have caused you.

  3. Steamroller Studios reporter

    No worries! It was a little tricky to track down but I'm glad we were able to correctly identify the problem on our side and that there was an easy fix for it on your side.

  4. Log in to comment