Author Topic: 4K Atlas constantly crashing on Add/Update  (Read 11860 times)

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
4K Atlas constantly crashing on Add/Update
« on: February 27, 2014, 06:11:28 AM »
Hi,
I'm fighting with a 4K atlas for 2 days. It contains lots of sprites at the moment(114). Everytime I try to add a sprite, i get an error:
Quote
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.Texture:Internal_GetWidth (UnityEngine.Texture)
  at UnityEngine.Texture.get_width () [0x00000] in <filename unknown>:0
  at UIAtlasMaker.PackTextures (UnityEngine.Texture2D tex, System.Collections.Generic.List`1 sprites) [0x000ec] in /Users/romainpedra/Git/AM2_Mobile/Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:144
  at UIAtlasMaker.UpdateTexture (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) [0x000b0] in /Users/romainpedra/Git/AM2_Mobile/Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:540
  at UIAtlasMaker.UpdateAtlas (.UIAtlas atlas, System.Collections.Generic.List`1 sprites) [0x0000c] in /Users/romainpedra/Git/AM2_Mobile/Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:640
  at UIAtlasMaker.UpdateAtlas (System.Collections.Generic.List`1 textures, Boolean keepSprites) [0x00024] in /Users/romainpedra/Git/AM2_Mobile/Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:623
  at UIAtlasMaker.OnGUI () [0x00bb5] in /Users/romainpedra/Git/AM2_Mobile/Assets/NGUI/Scripts/Editor/UIAtlasMaker.cs:985
  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 /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222

I have this error very often, but everytime I just retry and it's okay(more or less, I have to build the atlas 2 sprites by 2 sprites and Commit on Git between each update if I don't want to redo it everytime...)
It's not a size problem, because it's doing it with every sprite I want to add since I have 114 sprites.
The proof that there is still space in the atlas is attached to the topic.

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 4K Atlas constantly crashing on Add/Update
« Reply #1 on: February 27, 2014, 05:10:58 PM »
I see a lot of sprites in your atlas that can be easily shrunk by more than 95% of their size if you were to simply use sliced sprites.

All those buttons for example with text on them... why? Why not create a small sliced sprite for the background of the button, and put text on it using a label?

And the window background? That massive chat window can be created using several much smaller sliced sprites. One for the background (light gray area), one for the chat area (big darker gray area), one for the input field, and two regular sprites for the circular sprites.

Unfortunately I can't comment much on the original issue, but your atlas can be improved significantly.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: 4K Atlas constantly crashing on Add/Update
« Reply #2 on: February 27, 2014, 05:18:11 PM »
Hi,
It's not very obvious here but the graphist made some specific things on some sprites that make them non "sliceable" (sorry I don't know if the word exists ^^ )
Same thing for the buttons with texts, if I didn't made a sliced sprite from the assets, the graphist give me, this is because the text, for example, have some effects that I can't reproduce with NGUI.
Anyway, could it be a good idea to split my atlas in two or more parts to prevent me from these Atlas Maker "WTF" problems? (I know by reading the forum that the problem is not from you but from something inside Unity that is fucking the textures during the build)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 4K Atlas constantly crashing on Add/Update
« Reply #3 on: February 27, 2014, 05:30:35 PM »
If you're targeting mobile platforms, you will have to do it regardless, as 4k by 4k is too big for most devices.

I'd also advise moving the larger textures out, leaving them as regular textures that you would then draw using UITexture.

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: 4K Atlas constantly crashing on Add/Update
« Reply #4 on: March 04, 2014, 07:13:36 AM »
Hi,
We've done what you were saying and it's working fine now. It's a good lesson for the future, thank you for your advises.
Moreover, by moving the larger textures out, the app is using less memory.
Thank you !