Textures destroyed after AssetDatabase.SaveAssets

Hi,

I’m trying to create a texture manager that uses Unity’s texture packing, and update managed textures automatically when new textures are found on some predefined folders.

I’ve attached the interesting part of my class file : 1218005–49941–$TextureManager.cs (1.81 KB).

The problem is, sometimes, but not always, some of the loaded textures, but not always the sames, get destroyed after calling AssetDatabase.SaveAssets().

In the provided source code I made evidence of this by trying to log all loaded texture names : this is working fine before the call to the AssetDatabase.SaveAssets() function, and it sometimes crashes when trying to log after the call, with a message saying that the object should not be accessed anymore since it has been destroyed…

This is reproducible with Unity 3.5.7 and Unity 4.1.1.

Does anybody have any though about why this is happening ?

Just noticed this happening myself. Happens in NGUI when you create a brand new atlas the first time after starting Unity. Repeating the process right after getting the null exception works fine and doesn’t seem to happen ever again.

Bug?