EditorWindow loses Texture2D reference on scene change: how to handle?

I have a custom EditorWindow in which I'm implementing a Visio-like flowchart interface. To display the elements in the flowchart, my EditorWindow class just creates a new Texture2D(1, 1) in OnEnable(). That's all good and well, but if I switch to a new scene while the EditorWindow is open, I get spammed with errors that the Texture2D I'm trying to reference has been destroyed.

I guess it's curious that a Texture2D I've created programatically as a member of a class instance that's NOT being destroyed is getting destroyed by Unity without my knowledge, but more to the point... is there any way I can know that a) the asset has been destroyed, so I can recreate it, and/or b) the scene has been changed, so I can (again) recreate the asset?

Or am I just doing horrible violence to the editor in the first place? ^_^

The way I found to surpass this, is to load the texture OnEnable() but only if the variable is null, and to dispose of it OnDestroy() to avoid un-needed memory allocation... good luck!

Why not create the texture AND save it to some temp location within your project? Then OnEnable(), you can read it in again if it has been lost in scene transition? I don't know where I got the idea, but I THINK if you create a Texture2D on the fly like that, it's actually created in your scene, but just never shows up, and is never saved.

I’m facing similar, even though I saved the Texture2d reference in a static variable. I think its because the Texture2d is created inside the scene, and cleared when reloading.

This is an old question, but it’s still easy to get here with this problem, so I’ll post my solution:

When you create the texture, set the hideFlags to DontSaveInEditor. If you do this, remember to also Destory the texture manually (in OnDestroy for the editor window).