Unexpected destruction of object

I am having a problem with an unexpected destruction of a class attribute with the following code:

/* Defines an singleton EditorWindow */ public class MyEditor : Window {

private Texture2D lineTexture;

void Awake() {
    // Create an AA line standard texture.
    lineTexture = new Texture2D(1,2);
    Color transparentWhite= new Color(1, 1, 1, 0);
    Color opaqueWhite     = new Color(1, 1, 1, 1);

void OnGUI() {
    // Code to compute the Bezier start,end, startTangent, endTangent, etc...

    // Use a Bezier for the connections.
    // HERE THE "lineTexture" HAS BEEN DESTROYED !!!!!  WHY ????
Handles.DrawBezier(start, end, startTangent, endTangent, color, lineTexture, 1.5f);


The "lineTexture" object has been destroyed before the first call to OnGUI(). It is not used anywhere else in the code. "MyEditor" is a singleton. I have verified (using MonoDev) that "Awake" does get called before "OnGUI". It is a mystery for me that "lineTexture" get destroyed. Any help in understanding this situation is appreciated....

Cheers, ...reinual

You may want to use OnEnable instead of Awake - if you check the EditorWindow documentation, Awake isn't listed as a valid message sent, even if it is fired. What'll happen is that the object will be created and destroyed over time, but Awake will only be called once, whereas OnEnable will be called every time

Thanks for this catch but it does not resolve the problem. I have move the creation of the lineTexture in the OnEnable() but it does not have any effect on the fact that when "OnGUI" gets called the "lineTexture" has already been destroyed resulting in a crash.

For now, I have created a "lineTexture" texture and inserted it in Project. I read it into "lineTexture" and that is stable. I have an impression that a dynamically created texture does not survive. I can continue this way but I rather understand if dynamically created texture must be continuously refresh (as if they were created in GPU memory) or not.