[RESOLVED] When the Unity Editor Crashes

What’s the best way to debug my code with the Windows Unity Editor crashes? I can click debug and attach to visual studio.

I have some information like:

Unhandled exception at 0x03f0259c in Unity.exe: 0xC0000005: Access violation reading location 0x0000011c.

Is there a specific thread and a specific place I can look so that I can match up my code and find the true error?

Thanks

I’m using VS 2008.

I open Unity.exe as a solution.

I have a C# project with the same C# files that are compiled in Mono. I add this project as a solution.

When I attempt to debug with Unity as the start project, I get an error about the debug symbols missing and debugging stops.

If I run Unity as the start project the editor opens.

When I start my project in Unity, I get an access violation and can’t trap the exception.

The debugger gets stuck at the exception and the only option is to close/stop debugging.

Something odd here is that I can build the web player and that runs without crashing.

Only the Windows editor is crashing when I play the project.

2.1 and 2.5 versions of the editor on the mac are working okay.

The Unity 2.5 editor does a crash to desktop on my Vista 64-bit machine.

The Unity 2.5 editor works fine on my Vista 32-bit machine.

So this could potentially be a 64-bit issue or a hardware issue.

I tracked down the core issue. MyCustomObject that extends MonoBehavior was throwing a null reference exception. One was inside OnGUI, the other was inside FixedUpdate().

Null reference exceptions are really bad on Vista 64-bit and cause the Editor to crash.

The other platforms are a little bit more sturdy, but also failed to log the error.

Does not crash here on Vista64 if I have not assigned a component to a slot but try to use the slot.

Try throwing an exception in:

OnGUI() and FixedUpdate() and see if your editor crashes.

Here’s how to lock up the UI so that you can’t stop your game. I can reproduce on Vista 64-bit with Unity 2.5.

using UnityEngine;
using System.Collections;

public class MyCustomObject : MonoBehaviour
{

}

public class NewBehaviourScript : MonoBehaviour
{
    MyCustomObject m_myCustomObject = null;

    void OnGUI()
    {
        m_myCustomObject.enabled = !m_myCustomObject.enabled;
    }

    void FixedUpdate()
    {
        m_myCustomObject.enabled = !m_myCustomObject.enabled;
	}
}

137148–5038–$editorcrash_187.zip (1.08 MB)

I can confirm this! I was having the same problem (Unity crashes with no error dialog or even windows error dialog). It seems to happen if you try to change “enabled” on a component that doesn’t necessarily exist. For example I tried this:

void OnBecameInvisible()
	{
	enabled = false;
	_animation.enabled = false;
        renderer.enabled = false;
	_inGaze = false;
	}

This will immediately crash unity as soon as one of the objects becomes invisible. If I comment out renderer.enabled, it runs fine. There is a skinned mesh renderer attached to the same object (in a somewhat complicated hierarchy) so I don’t know why it would be null…

Sorry, I forgot to mention that this is running on XP 32-bit!

From what I can tell, it happened, when you tried to disable the SkinnedMeshRenderer!

In fact, this crash STILL occurs, if you enable/disable it from an animation.

To fix it, I wrote this little script:

using UnityEngine;

// Use this script if a SkinnedMeshRenderer causes unity to crash when enabling/disabling it from animation
internal class RendererAnimationHelper : MonoBehaviour
{
    public new float enabled = 1;

    public void Update()
    {
        renderer.enabled = (enabled == 1);
    }
}