Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: mindlube on February 13, 2013, 08:00:34 PM

Title: UIAtlasMaker exception
Post by: mindlube on February 13, 2013, 08:00:34 PM
I frequently see this exception when updating my atlas. After the exception, sometimes the atlas is updated, sometimes it is not. Kind of puzzled what's going on. Thinking about reverting back to TexturePacker instead. Has anyone else seen this problem and/or bug reported it?

MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
  at (wrapper managed-to-native) UnityEngine.Object:get_name ()
  at UIAtlasMaker.ExtractSprites (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) [0x00069] in /Users/alexr/Desktop/ChickenFoot/CD Unity project/Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:473
  at UIAtlasMaker.UpdateAtlas (System.Collections.Generic.List`1 textures, Boolean keepSprites) [0x00019] in /Users/alexr/Desktop/ChickenFoot/CD Unity project/Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:647
  at UIAtlasMaker.OnGUI () [0x008dc] in /Users/alexr/Desktop/ChickenFoot/CD Unity project/Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:923
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d0] in /Applications/buildAgent/work/27593436b7e20640/mcs/class/corlib/System.Reflection/MonoMethod.cs:222
Title: Re: UIAtlasMaker exception
Post by: ArenMook on February 13, 2013, 10:31:22 PM
Nope, can't say I've seen this.
Title: Re: UIAtlasMaker exception
Post by: Nexic on April 18, 2013, 03:15:19 PM
I have been having this problem today, was about to give up when I realized that all the problems started since I begun using the Cache Server. Disabled it and Atlases work like a charm again. Just thought the community here might like to know that one.
Title: Re: UIAtlasMaker exception
Post by: Bilko on June 15, 2013, 09:42:31 AM
When I try to create an atlas I get the following error also:

MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UIAtlasMaker.AddSprite (System.Collections.Generic.List`1 sprites, .SpriteEntry se) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:225)
UIAtlasMaker.ReplaceSprites (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:387)
UIAtlasMaker.UpdateAtlas (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:563)
UIAtlasMaker.UpdateAtlas (System.Collections.Generic.List`1 textures, Boolean keepSprites) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:620)
UIAtlasMaker.OnGUI () (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:903)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)


I am using NGUI 2.6.2 2.6.3 is not on the asset store yet.

I thought it was a FastGUI issue however it does the same error even when I remove anything fast GUI related.

Any ideas on how to fix this? Note I do not have the cache server enabled like the previous user.

Thanks
Title: Re: UIAtlasMaker exception
Post by: ArenMook on June 15, 2013, 05:58:18 PM
Make sure you save after every modification to the atlas and restart Unity for good measure.
Title: Re: UIAtlasMaker exception
Post by: Bilko on June 17, 2013, 04:49:57 AM
Hello again;

I can not even create an altas, the ONLY way I can get it to build is if I uncheck the PMA shader, however then the atlas is not correct. I can not update the atlas or anything with that checked.

I hope this gives you a little insight to the issue. I look forward to your reply.

Thanks
Title: Re: UIAtlasMaker exception
Post by: ArenMook on June 17, 2013, 10:11:40 PM
I've narrowed down the issue. It only happens the very first time you try to create an atlas in a brand-new instance of Unity. When it happens, delete the files it created (material, prefab, and texture), and re-do the atlas creation. Second time onwards works just fine.

I'll add in a proper fix to the next release.
Title: Re: UIAtlasMaker exception
Post by: ArenMook on June 17, 2013, 11:46:34 PM
http://forum.unity3d.com/threads/178091-Textures-destroyed-after-AssetDatabase-SaveAssets
Title: Re: UIAtlasMaker exception
Post by: ArenMook on June 18, 2013, 12:16:16 AM
2.6.3 has the fix.
Title: Re: UIAtlasMaker exception
Post by: CazicThule on June 30, 2013, 08:03:01 AM
Got the latest version, restarted Unity and I'm still getting this error. I'm not using "cache server". Can't add anything to an atlas...
Title: Re: UIAtlasMaker exception
Post by: ArenMook on June 30, 2013, 09:55:44 PM
Verify that you actually have the latest version. Open up your readme file -- what version does it say you have?
Title: Re: UIAtlasMaker exception
Post by: CazicThule on July 01, 2013, 05:01:44 AM
ReadMe - 2.6.3
Title: Re: UIAtlasMaker exception
Post by: Lexile on July 01, 2013, 05:07:00 AM
Updated my Unity editor to 4.2.0f1 and I'm getting this bug now. Two things happen when I touch atlases now:

1. I get the error message described in OP's message -> Can't add any new sprites.

2. Even if the atlas maker doesnt add/update anything, the behaviour of some sprites change. Ie. a stretched sliced sprite i'm using as a background suddenly becomes pixelated, and I can't fix it without reverting to a backup project file.
Title: Re: UIAtlasMaker exception
Post by: ArenMook on July 01, 2013, 11:38:14 PM
An issue in the latest beta, perhaps?

The original issue is not possible because the code is completely different there now. Texture is never used directly anymore. Its name is saved and used instead. I need new line numbers and console log of the issue you are running into.
Title: Re: UIAtlasMaker exception
Post by: Lexile on July 02, 2013, 01:32:30 AM
Seems the lates beta wasn't somehow wasn't compatible with my old project. Started a new one and I don't seem to be getting any of those errors any more, even though had to redo a couple of hours of work.
Title: Re: UIAtlasMaker exception
Post by: miyudreams on July 02, 2013, 11:10:25 PM
Hey, just got this problem today on NGUI v2.6.3, "MissingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it." I didn't pay any attention to the stack trace. (should be a similar issue)

In my case it was because I updated the atlas, and there's a texture in the atlas that disappeared. But this texture was still being used in a widget added to my scene. Once I click on the "missing" texture and Add it back into the Atlas, I stopped getting this error. First of all, i don't know how the texture disappeared from my atlas. I only selected a bunch of textures that are currently in my atlas, and clicked the Add/Update button in the Atlas Maker, & I was changing the Padding property in the Atlas Maker.
Title: Re: UIAtlasMaker exception
Post by: CazicThule on July 05, 2013, 05:08:38 AM
I'm not using the beta, I'm using 4.1.5f1
Title: Re: UIAtlasMaker exception
Post by: ArenMook on July 05, 2013, 08:24:11 AM
That's what I use and I am able to create atlases just fine. I need some repro steps to go any further.
Title: Re: UIAtlasMaker exception
Post by: CazicThule on July 05, 2013, 05:16:53 PM
Creating atlases works fine the first time, but any subsequent additions will get the Texture2d exception
Title: Re: UIAtlasMaker exception
Post by: ArenMook on July 05, 2013, 08:12:41 PM
Again, works just fine. What's your target platform?
Title: Re: UIAtlasMaker exception
Post by: Bilko on July 18, 2013, 07:35:55 AM
I have NGUI 2.6.3 installed on Unity 4.1.5 and I still get the 2D texture error. Any ideas of a fix ?
Title: Re: UIAtlasMaker exception
Post by: ArenMook on July 18, 2013, 09:50:48 AM
I don't even know how to reproduce the issue, let alone fix it. As I mentioned, I am not seeing it in Unity 4.1.5 + NGUI 2.6.3 on Windows.
Title: Re: UIAtlasMaker exception
Post by: Bilko on July 19, 2013, 05:01:24 AM
I am on a mac using Unity 4.1.5 + NGUI 2.6.3. I understand your not seeing it on your windows machine, but myself and quite a few others are getting this error (maybe only mac users). Is there a mac that you can borrow to try and trouble shoot this problem? Because the product is unusable in it's current state.

Thanks
Title: Re: UIAtlasMaker exception
Post by: ArenMook on July 20, 2013, 04:08:23 AM
Yup, I will look into it.
Title: Re: UIAtlasMaker exception
Post by: ArenMook on July 20, 2013, 04:13:07 AM
I see it happening the first time you try to add a texture, but works fine the 2nd time you do it. I will look into why this is happening the first time you append a texture to an atlas, but in the meantime, just hit the add button a 2nd time and it will work from that point onwards. Certainly not "unusable".
Title: Re: UIAtlasMaker exception
Post by: ArenMook on July 20, 2013, 04:20:59 AM
Awesome... I can't reproduce it again. I think I have to restart the computer for it to happen.
Title: Re: UIAtlasMaker exception
Post by: devfo on September 03, 2013, 09:32:33 PM
I am getting this error every time and cannot get past it.
I am using Unity version 4.2.1. I can create a new atlas, but cannot update it. I have to delete my atlas and recreate it every time i want to update it. This is getting really annoying
Title: Re: UIAtlasMaker exception
Post by: ArenMook on September 04, 2013, 04:32:57 AM
Check the previous posts here. The answer is always the same. I cannot reproduce it. I cannot fix what I cannot reproduce. The issue goes away by restarting Unity, and there are no clear steps on how to reproduce the problem.

Here's a video in case you don't believe me:

http://www.screencast.com/users/ArenMook/folders/Camtasia%20Studio/media/0556a735-e7a7-4ea5-830a-0ce81bcff8f1
Title: Re: UIAtlasMaker exception
Post by: devfo on September 04, 2013, 09:59:59 AM
Just because you cannot reproduce it, doesn't suggest the bug does not exist. Especially since I am not the only one with this issue. I attached screen shots of the bug showing the exact details. As of now, i cannot get past this bug even if i restart unity, start a new project, etc...
Good thing I don't tell my customers (Bank of America, Prudential Investments) that I cannot reproduce their bugs. Instead I ask for more details, program information, sample data, environment setup, other software being used. After that, I will do some remote debugging on their systems to see the exact issue.
Guess I will fix it myself. I will update you when I find the fix...
Thanks
Title: Re: UIAtlasMaker exception
Post by: devfo on September 04, 2013, 11:35:22 PM
file: UIAtlasMaker.cs
Function: static bool PackTextures (Texture2D tex, List<SpriteEntry> sprites)

Error occurs on line # 150: if (Mathf.RoundToInt(rect.width) != textures\[i\] .width) return false;

It seems that textures is null. But i am not sure why.
if I comment out this line or RETURN if texture is null, it does not error. However the atlas maker will only add 1 image to the atlas. It will not loop and add all textures.

EDIT:
Seems that the issue is with your checking of Unity versions:
#if UNITY_3_5 || UNITY_4_0
changed to
#if UNITY_3_5 || UNITY_4_2

by doing this I am able to create a "one time" atlas. However I cannot update it. So I have to wipe it out, select ALL sprites to be added, then press add/update all.

Please test your code with the latest Unity 4.2 build.....
Title: Re: UIAtlasMaker exception
Post by: ArenMook on September 05, 2013, 05:02:00 AM
I never said the bug does not exist. This post shows that it does for some rare individuals. I simply said I cannot fix what I cannot reproduce. If you post clear steps on how I can reproduce it starting from a clean NGUI project, I will fix it, guaranteed.

I used Unity 4.2.1 in that video.
Title: Re: UIAtlasMaker exception
Post by: Gorgor on September 05, 2013, 10:30:43 AM
Today we found out that we are getting similar error:

  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 ()
  4. UITexturePacker.PackTextures (UnityEngine.Texture2D texture, UnityEngine.Texture2D[] textures, Int32 width, Int32 height, Int32 padding, Int32 maxSize) (at Assets/NGUI/Scripts/Editor/UITexturePacker.cs:89)
  5. UIAtlasMaker.PackTextures (UnityEngine.Texture2D tex, System.Collections.Generic.List`1 sprites) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:142)
  6. UIAtlasMaker.UpdateTexture (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:526)
  7. UIAtlasMaker.UpdateAtlas (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:617)
  8. UIAtlasMaker.UpdateAtlas (System.Collections.Generic.List`1 textures, Boolean keepSprites) (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:600)
  9. UIAtlasMaker.OnGUI () (at Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:921)
  10. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/b59ae78cff80e584/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

I try to update NGUI to the 2.6.5b from Asset store but it solved nothing:(.. We are using unity 4.1.2 on Macs.
It definitely worked few days ago.. unfortunately I don't know what happened:(
As devfo said - I can create new atlas.. but I can not update it:(
Title: Re: UIAtlasMaker exception
Post by: Gorgor on September 05, 2013, 10:49:44 AM
Hi,
I tried few versions back in SVN and tracked that problem.. Now I can confirm that my problem starts when I import into my project (already with NGUI) package named "Uni2D". It reports no errors and Uni2D works fine.. but NGUI becomes unable to update its own atlases... :(

EDIT:
After deleting Uni2D directory.. NGUI works again..
Hey guys.. you should really cooperate.. both packages seem super cool.. I do NOT want to be forced to choose one of them..

EDIT2:
Seems I am not the first one that found out that coexistence with Uni2D is problematic
http://www.tasharen.com/forum/index.php?topic=5287.0
Title: Re: UIAtlasMaker exception
Post by: FodderMK on September 05, 2013, 12:41:48 PM
I was having a similar problem.  The solution for me was to create a new, empty scene before I tried to manipulate the atlas.  Everything seemed to work as long as I didn't have a scene open that used atlas assets.  It's mildly irritating to close/reopen scenes in order to change my atlas but at least I can continue working.
Title: Re: UIAtlasMaker exception
Post by: ArenMook on September 05, 2013, 08:32:12 PM
Uni2D must be doing something with the textures that's causing them to get unloaded. Maybe it modifies the texture importing process? I'd post a bug on the Uni2D support forum.

Or just use Unity 4.3 beta. It already has native 2D support, so Uni2D, 2D Toolkit, ex2D, etc all become obsolete.
Title: Re: UIAtlasMaker exception
Post by: devfo on September 11, 2013, 12:41:58 AM
I also am using Uni2D. OK, sounds like this is the issue. Thanks for clearing this up guys...
Title: Re: UIAtlasMaker exception
Post by: Muxeu on September 25, 2013, 07:00:42 AM
Hi everyone ! A also catch this bug at my project. I fixed it by adding this line:
  1. sprite.tex.hideFlags = HideFlags.HideAndDontSave;
at UIAtlasMaker class in function ExtractSprites after this lines:
  1. SpriteEntry sprite = new SpriteEntry();
  2. sprite.name = asp.name;
  3. sprite.temporaryTexture = true;
  4. sprite.tex = new Texture2D(newWidth, newHeight);

It works for me ! Looks like unity gc clear textures after reimporting main atlas at this line:
  1. // The atlas no longer needs to be readable
  2. NGUIEditorTools.ImportTexture(atlas.texture, false, false);

Sorry for my bad english.
Title: Re: UIAtlasMaker exception
Post by: ArenMook on September 25, 2013, 07:36:34 PM
I'd be concerned with that potentially leaking memory since the textures wouldn't be marked as "don't save".
Title: Re: UIAtlasMaker exception
Post by: Muxeu on September 26, 2013, 01:28:25 AM
I'd be concerned with that potentially leaking memory since the textures wouldn't be marked as "don't save".

It's better than non-working atlas maker. At my large project maker not working at all without this fix (empty scenes and other hacks doesn't help). I am not using Uni2D or other toolkits.

As i see, maker crash only at large project and large atlases (my atlas 2048x2048, about 100 sprites). At small and new atlases works fine.
Title: Re: UIAtlasMaker exception
Post by: ArenMook on September 26, 2013, 03:52:56 PM
As Uni2D maker mentioned in the other thread, this problem gets fixed on Uni2D side in the next update.
Title: Re: UIAtlasMaker exception
Post by: wcoastsands on March 03, 2014, 08:51:45 AM
I get this error consistently when making 4k atlases (120 sprites each). Issue would occur when adding/updating an atlas. Was able to get around it by hitting the replace button, but now that that button has been removed in recent updates, I can't work around the issue anymore. The Updating window also remains on screen, making it impossible to do much with Unity other than force quit and try again.

Running Unity 4.3.4 with NGUI 3.5.3 on OSX 10.9.2 with 16GB Ram.
Title: Re: UIAtlasMaker exception
Post by: ArenMook on March 03, 2014, 11:10:14 PM
Can you send me your atlas and the sprite you're trying to add so I can look into this? You can either attach it here or email me the download link to support at tasharen.com.
Title: Re: UIAtlasMaker exception
Post by: wcoastsands on March 04, 2014, 06:14:21 AM
Just emailed you a download link. Thanks!
Title: Re: UIAtlasMaker exception
Post by: Acheron Studio on March 04, 2014, 05:17:55 PM
So I just got this issue today. It seems to have sorted itself out, so I can only supply what I 'think' I did, and what I think might potentially be the issue.

Here's the original story:
My textures were of Texture Type: GUI
My resulting atlas was of 2k x 4k (considered 'large' when it gets to around 4k)
It would halt on the updating bar while also throwing the error about Texture2D.

Here were 2 things I did that seemed to fix it (not suggesting it's the solution, just saying that after I did these, it worked. Might  be a clue):
I changed my textures to be of type Advanced and made sure Non power of 2 was set to None.
I added one less texture so that my resulting atlas was only of size 2k x 2k

I'm not using Uni2D or anything like that. I'm on the latest version of Unity and NGUI - or at the very least, on a very recent version.

Hope this helps. Cheers.

EDIT:

Completely disregard what I said. Apparently this still happens.

However I can confirm that clicking the Add/Update All button again after it was halting on the Updating progress bar did in fact complete the Atlas.
Title: Re: UIAtlasMaker exception
Post by: biggsthecat on March 20, 2014, 11:19:18 AM
Hey, I'm using version 3.4.9 and I'm having a similar issue trying to update the atlas. I'm trying to make an equipment inventory atlas and I keep getting an error saying:

"MissingReference Exception: The object of type 'Texture2D' has been destroyed but you are still trying to access it"

after trying to update. The atlas maker also never finished updating the atlas. It gets to the end of the loading bar, and stops so I can click Add/Update again. Once or twice, clicking the update button again will add the image to the atlas, but more often than not it will restart the update bar and never finish the update.

When it works fine, it moves onto a "Hold On" Loading bar, and adds the image from it's destination folder.

 I've read through many of the atlas maker posts and have found nothing that consistantly works. I've tried waiting for longer times, clicking add/update multiple times, and adding the short line of script to the UI Atlas Maker script:

"sprite.tex.hideFlags = HideFlags.HideAndDontSave;"

as posted by Muxeu but it's made no difference. I've also tried it on different computers and it makes no change. Any assistance would be appreciated.
Title: Re: UIAtlasMaker exception
Post by: ArenMook 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
Title: Re: UIAtlasMaker exception
Post by: biggsthecat 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.
Title: Re: UIAtlasMaker exception
Post by: ChaoticBoredom 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
Title: Re: UIAtlasMaker exception
Post by: NateJC 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):
(http://i.imgur.com/uPJtVXs.png)

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;

Here are all of my Atlas settings:
(http://i.imgur.com/tCeGe7P.png)
(http://i.imgur.com/0rPmzA4.png)
(http://i.imgur.com/awwes72.png)

And here are the settings of the image that I'm attempting to update:
(http://i.imgur.com/S7nX0Nv.png)

I am completely stuck and not sure how to go on without re-doing a significant amount of work  :(
Title: Re: UIAtlasMaker exception
Post by: ArenMook 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.
Title: Re: UIAtlasMaker exception
Post by: braxiatel 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
Title: Re: UIAtlasMaker exception
Post by: Nicki 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. :(
Title: Re: UIAtlasMaker exception
Post by: alexkring 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.
Title: Re: UIAtlasMaker exception
Post by: ArenMook 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?
Title: Re: UIAtlasMaker exception
Post by: Xeno97 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.  
Title: Re: UIAtlasMaker exception
Post by: alexkring 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.  
Title: Re: UIAtlasMaker exception
Post by: skullthug 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.
Title: Re: UIAtlasMaker exception
Post by: ArenMook on January 08, 2015, 08:48:51 AM
I can't comment on that much because 3.6.7 predates this topic.
Title: Re: UIAtlasMaker exception
Post by: Nicki 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.
Title: Re: UIAtlasMaker exception
Post by: AtomicBob 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 (http://docs.unity3d.com/ScriptReference/Resources.UnloadUnusedAssets.html)

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.