Author Topic: UIAtlasMaker exception  (Read 33634 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAtlasMaker exception
« Reply #45 on: March 20, 2014, 12:32:04 PM »
You can try sending me your atlas and the image you're trying to add to support at tasharen.com

biggsthecat

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIAtlasMaker exception
« Reply #46 on: March 21, 2014, 11:19:27 AM »
Okay, I think I identified the problem. I opened a new scene, deleted NGUI and re-imported it. It worked fine for a while again, and I managed to add a few images to the Atlas. At some point, I thought it was taking too long so I tried clicking on something else or navigating through the project. The atlas maker stopped working again, so I reimported it once again.

I've been very patient waiting for images to add to the atlas and so far have had no further errors.

So maybe just not pressing anything until the atlas has finished what it's doing is all that needs to be done, and delete and re-import the Asset in a new scene if it breaks.

ChaoticBoredom

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
    • Life Goes On
Re: UIAtlasMaker exception
« Reply #47 on: March 26, 2014, 02:56:49 AM »
I have also been experiencing this issue, and haven't been able to import/update and sprites in my atlas since it started at some point today. In order to update images, I've either had to update all of the images at the same time, or build a new atlas. The first is workable, the second is not.

Each time I try to run Atlas Maker, I do notice that it changes the import settings of files that it fails on, and on the atlas.png as well. It doesn't seem to matter what image I try to update, and it doesn't matter whether it is in the atlas or not.

The error I get:
  1. MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.
  2. Your script should either check if it is null or you should not destroy the object.
  3. UnityEngine.Texture.get_width () (at C:/BuildAgent/work/ea95e74f6e5f192d/Runtime/ExportGenerated/Editor/Graphics.cs:682)
  4. UIAtlasMaker.PackTextures (UnityEngine.Texture2D tex, System.Collections.Generic.List`1 sprites) (at Assets/Editor/NGUI/UIAtlasMaker.cs:144)
  5. UIAtlasMaker.UpdateTexture (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) (at Assets/Editor/NGUI/UIAtlasMaker.cs:558)
  6. UIAtlasMaker.UpdateAtlas (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) (at Assets/Editor/NGUI/UIAtlasMaker.cs:673)
  7. UIAtlasMaker.UpdateAtlas (System.Collections.Generic.List`1 textures, Boolean keepSprites) (at Assets/Editor/NGUI/UIAtlasMaker.cs:656)
  8. UIAtlasMaker.OnGUI () (at Assets/Editor/NGUI/UIAtlasMaker.cs:1002)
  9. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
  10.  

The following are the file diffs on the metas, showing the altered import settings on the attempted update file and the atlas.png

white_pixel.png.meta

     externalNormalMap: 0
     heightScale: .25
     normalMapFilter: 0
-  isReadable: 0
+  isReadable: 1
   grayScaleToAlpha: 0
   generateCubemap: 0
   seamlessCubemap: 0
-  textureFormat: -1
+  textureFormat: 5
   maxTextureSize: 1024
   textureSettings:
     filterMode: -1
     aniso: -1
     mipBias: -1
     wrapMode: -1
-  nPOTScale: 1
+  nPOTScale: 0
   lightmap: 0
   compressionQuality: 50
   alphaIsTransparency: 0


Atlas.png.meta

@@ -16,7 +16,7 @@
     externalNormalMap: 0
     heightScale: .25
     normalMapFilter: 0
-  isReadable: 0
+  isReadable: 1
   grayScaleToAlpha: 0
   generateCubemap: 0
   seamlessCubemap: 0
@@ -27,10 +27,10 @@
     aniso: 4
     mipBias: -1
     wrapMode: 1
-  nPOTScale: 1
+  nPOTScale: 0
   lightmap: 0
   compressionQuality: 50
-  alphaIsTransparency: 1
+  alphaIsTransparency: 0
   textureType: -1
   buildTargetSettings: []
   userData:


I have not changed any of my settings in Atlas Maker, nor have I seen any import settings altered when making/updating an atlas before. May just be a symptom of the larger problem, but maybe helpful.

I am using Unity 4.2.2f1 and NGUI 3.5.4 r2

NateJC

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIAtlasMaker exception
« Reply #48 on: June 15, 2014, 11:26:48 PM »
I am also having this issue (Unity 4.3.4f1, NGUI 3.5.9, Mac OS X 10.9.3):


It's when I'm trying to update 1 image within a particular atlas, it crashes every time. The error message is the same as everyone else has mentioned and seems to be caused by a null reference in UIAtlasMaker.cs line 147:
  1. if (Mathf.RoundToInt(rect.width) != textures[i].width) return false;
  • Restarting Unity didn't fix it
  • Trying to update twice didn't fix it
  • Creating a blank scene before updating the atlas didn't fix it

Here are all of my Atlas settings:




And here are the settings of the image that I'm attempting to update:


I am completely stuck and not sure how to go on without re-doing a significant amount of work  :(
« Last Edit: June 16, 2014, 12:52:26 AM by NateJC »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAtlasMaker exception
« Reply #49 on: June 16, 2014, 08:24:16 AM »
You seem to be using a 4k size atlas texture -- a bad idea in general, especially if you plan on targeting mobile devices as majority won't support texture sizes above 2048x2048. Unity's handling of this is not consistent either, and in some cases it tries to "correct" your texture size, messing it up for NGUI.

That said, I don't know if this is what's causing your issue, but first thing you should always do is update to the latest version. If that doesn't help, you can try to reproduce the issue in a clean project (just copy your atlas over there). If it still happens, send me the atlas and the texture you're trying to add to support at tasharen.com.

To this day I've not had a single repro case to look at that shows this problem consistently enough for me to reproduce it on my end.

braxiatel

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UIAtlasMaker exception
« Reply #50 on: July 28, 2014, 04:53:36 AM »
I had this issue today, on a project I've been working on for a while without any issues. It occurred when added artwork I received from my artist without first checking the dimensions. My Atlas is already at 2048x2048 and I had tried to add a new image that turned out to be 1000x1000 in size. Resizing down to a more realistic size stopped the error from occurring.

Might be worth checking for any oversized images? Or splitting into atlases that are 2K max? Hopefully I can finish this project before I push the dimensions higher with legitimate textures!

It'd be useful if this exception could be handled more gracefully. The progress bar doesn't clear and I can't interact with Unity. A force quit is required.

As an FYI I am also using OS X. SystemInfo.maxTextureSize on my MacBook is 8192. Not sure if that's important, but provided for information.

NGUI: 3.6.8, Unity: 4.5.2f1, OS X 10.9.4

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIAtlasMaker exception
« Reply #51 on: July 28, 2014, 02:37:03 PM »
Unity itself doesn't eat bigger than 4096 because reasons.

If I got these errors consistently, I'd Debug.Log every textures[index] names out to make sure which was making trouble, or if the whole list was cleared somehow. I have yet to be able to reproduce this error though. :(
« Last Edit: July 29, 2014, 04:29:40 PM by Nicki »

alexkring

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 3
    • View Profile
Re: UIAtlasMaker exception
« Reply #52 on: July 29, 2014, 12:27:31 PM »
I've been able to reproduce this bug, and I have a temporary fix.

Here are my repro steps:
1. Create an atlas with about 70 100x100 icons, with the following options checked in the Atlas Maker
- Trim Alpha
- Truecolor
- Force Square
This should result in a 2048x2048 texture that is about half-full.
2. Select all of the icons again, and hit the "Add/Update" button to update them all.
3. Observe errors.

The bug is difficult to reproduce because it is dependent on your computer hardware. More specifically, it is dependent upon how long the garbage collection takes.

The problem is this: NGUI is creating temporary textures during atlas creation. Unity is destroying these textures when AssetDatabase.Refresh is called (ex: through NGUIEditorTools.ImportTexture), since this triggers a Resources.UnloadUnusedAssets. The temporary textures will then be unloaded from memory, and set to null.

My solution was to create a temporary gameobject when a temporary texture is created inside the CreateSprites function. I also create a temporary material, and assign the temp texture to this material. When ReleaseSprites is called, I destroy that gameobject.

Here is another helpful tip for more clearly understanding this bug. Go to around line 665 of the UIAtlasMaker.cs file, within this function 

UpdateAtlas (List<Texture> textures, bool keepSprites)

Right after the call to CreateSprites, iterate through each SpriteEntry, and print a log message if the texture of any of those entries is set to null. You should see that at this point, if you have a large number of textures to update, the temporary textures will have their texture set to null.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAtlasMaker exception
« Reply #53 on: July 30, 2014, 10:05:10 AM »
Thanks for investigating this, alex. Question though -- you say you create a game object and a material. But that's not enough -- to reference a material on the game object you would need a renderer. What is it you're doing exactly? Can you post some code?

Xeno97

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 1
    • View Profile
Re: UIAtlasMaker exception
« Reply #54 on: July 30, 2014, 03:34:29 PM »
I recently got the same error as the OP when trying to recreate a texture that was too large. After adding a null check above the error line in UIAtlasMaker (code below), it correctly stopped and showed an error telling me that the texture would be too big. Probably related to Unity trying to resize the texture for us, which means the texture we thought we had is no longer valid.

  1. ...
  2.  
  3. for (int i = 0; i < sprites.Count; ++i)
  4. {
  5.     Rect rect = NGUIMath.ConvertToPixels(rects[i], tex.width, tex.height, true);
  6.  
  7.     /******************* ADDED *******************/
  8.     // Check if the texture is gone before using it
  9.     if(textures[i] == null)
  10.     {
  11.         return false;
  12.     }
  13.     /***************** END ADDED! *****************/
  14.  
  15.     // Make sure that we don't shrink the textures
  16.     if (Mathf.RoundToInt(rect.width) != textures[i].width) return false;
  17.  
  18. ...
  19.  

alexkring

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 3
    • View Profile
Re: UIAtlasMaker exception
« Reply #55 on: July 31, 2014, 06:41:18 PM »
Here is the main block of code for creating the temporary gameobject.

  1.    // I needed to assign the temporary texture to a GameObject, because otherwise the texture will be unloaded
  2.            // whenever AssetDatabase.Refresh is called (this triggers a call to Resources.UnloadUnusedAssets). We
  3.            // need for this texture to be in memory while creating atlases in the editor.
  4.            sprite.temporaryGameObject = new GameObject(sprite.name);
  5.            MeshRenderer mr = sprite.temporaryGameObject.AddComponent<MeshRenderer>();
  6.            Material tempMaterial = new Material( NGUISettings.atlas.spriteMaterial );
  7.            mr.sharedMaterial = tempMaterial;
  8.            mr.sharedMaterial.SetTexture("_MainTex", sprite.tex);
  9.  

skullthug

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 37
    • View Profile
Re: UIAtlasMaker exception
« Reply #56 on: January 07, 2015, 09:00:18 PM »
Just wanted to post and say I'm having this issue as well, suddenly out of the blue. Using Unity 4.5.2f1 and NGUI 3.6.7. [unable to update to latest due to project restrictions]
It's occurring on an a 1024x1024 atlas with a large number of sprites.

Xeno97's code prevents the error from happening, but I'm still unable to update an atlas. I've checked all the Atlas texture import settings and it doesn't appear like it's being resized to anything too small.

I attempted alexkring's method of creating a temporary object during CreateSprites, but it doesn't appear to be working for me unfortunately.

I have found a very confusing workaround, which is basically to update a smaller atlas of 256x256 (containing three sprites). Once it successfully updates, I can then update the troublesome Atlas correctly but only once. That is, if I literally just press Add/Update again after it's successfully finishes it will then start giving me the error again.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIAtlasMaker exception
« Reply #57 on: January 08, 2015, 08:48:51 AM »
I can't comment on that much because 3.6.7 predates this topic.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIAtlasMaker exception
« Reply #58 on: January 10, 2015, 04:53:45 PM »
It might be that the atlas needs to be bigger than 4k*4k in which case all hell breaks loose. Check the size of the atlas without that sprite, and add it individually afterwards. You could try to do this in a secondary atlas to test it.

I'm just reaching for straws though; it sounds weird.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: UIAtlasMaker exception
« Reply #59 on: March 24, 2016, 03:03:37 PM »
I just tracked down this problem as well and noticed something mildly interesting. According to the documentation

Quote
An asset is deemed to be unused if it isn't reached after walking the whole game object hierarchy, including script components. Static variables are also examined.

A quick test seems to confirm this applies to editor scripts like UIAtlasMaker. We're using an older version of NGUI (3.6.5) and can't upgrade this late in a project, so rather than merge in the hack from newer NGUI versions, I just add and remove the temporary textures from a static list. It's still a hack, but it's a bit simpler at least.