- Home /
Handling NullReferenceException in EditorWindow OnGUI()
I'm working on a custom EditorWindow, but any time I encounter what should throw a NullReferenceException in OnGUI(), the Unity Editor hangs instead.
Example Code:
// C# example:
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class MyWindow : EditorWindow
{
// Add menu named "My Window" to the Window menu
[MenuItem ("Window/My Window")]
static void Init ()
{
// Get existing open window or if none, make a new one:
MyWindow window = (MyWindow)EditorWindow.GetWindow (typeof (MyWindow));
}
void OnGUI ()
{
List<int> mynewList = null;
Debug.Log(mynewList.Count);
}
}
If I open this window via Window->My Window, my unity.exe instantly freezes and must be killed via the Task Manager. Even if I use try...catch blocks in an attempt to catch the exception, it still hangs. Is there a better way of debugging NullReferenceExceptions in EditorWindows without having to restart Unity every time one is hit?
Using Unity3D 3.5.0f5
Your answer
Follow this Question
Related Questions
EditorWindow & Handles Position/FreeMove/... 1 Answer
Editor GUI Drag Selection Box 1 Answer
How to get an array inside a simple class at Editor window and change arraysize? 0 Answers
How to resize preference window to fit gui contents. 1 Answer
Texture2D is Null even though hooked up in Inspector. 0 Answers