Editor Window Crashing.. Help

Hey Guys,

I am creating a script that draws a bunch of random boxes in an editor window, gives them a random colour. This script was seen from the Unite 2011 intro to editor scripting, looked like fun so thought I would give it ago… But its not working… it keeps crashing unity. Could anyone enlighten me as to why?

Here is my script:

using UnityEngine;
using System.Collections;
using UnityEditor;

public class BlockPainter : EditorWindow {
	
	[MenuItem("Level Editor/Block Painter")]
	
	public static void ShowBlockPainterrWindow () {
		var window = GetWindow <BlockPainter>();
		window.title = "Block Painter";
	}
	
	private Color[] pixels;
	private int width;
	private int height;
	
	public void OnEnable () {
		width = height = 8;
		pixels = new Color[width * height];
		
		for(int i = 0; i < pixels.Length; i++){
			pixels[i] = new Color(Random.value, Random.value, Random.value, 1.0f); 	
		}
	}
	
	public void OnGUI () {
		var oldColor = GUI.color;
		
		GUILayout.BeginHorizontal();
		for(int i = 0; i < width; i++){
			GUILayout.BeginVertical();
			for(int j = 0; i < height; j++){
				GUI.color = pixels[j + i * height];
				GUILayout.Box(GUIContent.none, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
			}
			GUILayout.EndVertical();
		}
		GUILayout.EndHorizontal();
		GUI.color = oldColor;
	}
}

Thanks.

It does not crash on my machine. I’m running Windows 7 and Unity version 3.5.5.f3.

Have you tried looking in the editor log? (Console Window->Open Editor log)

I’ve run into the same problems. The issue was that the filename of my script doesn’t match the class-name of the EditorWindow inside the script.
Check if your script has the filename BlockPainter.cs.