I created a custom editor in which I wanted to have alternating colors between elements, just like the console alternates the background color between multiple log entries.
to enclose each element, since I have multiple GUI components per element. To change the background color of BeginHorizontal, I dynamically created two textures and alternated them in the background color like this
This works great (as opposed to GUI.color or GUI.backgroundColor which don't change the color of a BeginHorizontal()). My only problem is once I save the scene, I get the following error:
Which is related to the two Texture2D's I create. But I have no idea where I have to free the textures since I am using them all the time in the editor window. As I said, the warning message occurs every time I save the scene.
Does anyone know how to fix these leaks?
asked Jun 23 '11 at 01:35 AM
Why not destroy the textures as soon as you exit the for loop? It doesn't look like they are needed anymore. Your code is going to re-create them every time that function is called.
It seems to me that it would make more sense to create your textures outside your code and assign them in the inspector. Is there some reason you want to create new textures from scratch every frame?
Personally I would just use two different GUIStyles and alternate each time through the loop: