Author Topic: OutOfMemoryException: Out of Memory NGUI 3.7.1  (Read 3799 times)

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
OutOfMemoryException: Out of Memory NGUI 3.7.1
« on: August 30, 2014, 12:10:04 PM »
I'm getting the following error from NGUI:

Quote
OutOfMemoryException: Out of memory
BetterList`1[UnityEngine.Vector2].AllocateMore () (at Assets/NGUI/Scripts/Internal/BetterList.cs:178)
BetterList`1[UnityEngine.Vector2].Add (Vector2 item) (at Assets/NGUI/Scripts/Internal/BetterList.cs:220)
UIBasicSprite.TiledFill (.BetterList`1 verts, .BetterList`1 uvs, .BetterList`1 cols) (at Assets/NGUI/Scripts/Internal/UIBasicSprite.cs:529)
UIBasicSprite.Fill (.BetterList`1 verts, .BetterList`1 uvs, .BetterList`1 cols, Rect outer, Rect inner) (at Assets/NGUI/Scripts/Internal/UIBasicSprite.cs:329)
UISprite.OnFill (.BetterList`1 verts, .BetterList`1 uvs, .BetterList`1 cols) (at Assets/NGUI/Scripts/UI/UISprite.cs:422)
UIWidget.UpdateGeometry (Int32 frame) (at Assets/NGUI/Scripts/Internal/UIWidget.cs:1459)
UIPanel.UpdateWidgets () (at Assets/NGUI/Scripts/UI/UIPanel.cs:1522)
UIPanel.UpdateSelf () (at Assets/NGUI/Scripts/UI/UIPanel.cs:1185)
UIPanel.LateUpdate () (at Assets/NGUI/Scripts/UI/UIPanel.cs:1144)

I saw a similar problem mentioned in this previous topic which seems to indicate that it was fixed as of 3.5.1, but I'm using 3.7.1 and am encountering this issue.

I think it may have something to do with the fact that I'm using Space for Unity which uses some pretty large meshes and another camera to things look very big and far away. The reason I suspect this is because my problems didn't start occurring until some time after I imported that into my project, and it only seems to happen in scenes where I have both NGUI and Space for Unity.

NGUI doesn't like something about it and I get lots of errors. It also slows down the editor to a crawl and has crashed it a couple of times. Please help me figure out how to resolve this!

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: OutOfMemoryException: Out of Memory NGUI 3.7.1
« Reply #1 on: August 31, 2014, 07:28:20 AM »
Well the stack trace shows you where to problem likely is: You're using a tiled sprite that tiles very very closely, think 1 pixel. Each time there's a tile, it adds vertices and some other things which eventually will fill your memory. Unity is only 32 bit, which means that the editor only ever has access to 4 gb ram, so if Space also takes up a lot of memory, both together likely cause this. The reason it's NGUI that causes the error, is that Space probably allocates its ram use before the tiled sprite does.

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: OutOfMemoryException: Out of Memory NGUI 3.7.1
« Reply #2 on: September 01, 2014, 01:31:57 PM »
Thanks. That's useful to know. But my question is: Why is NGUI making it so tiny? I designed it at 1280x720 resolution, but because of the Space Camera (or something) NGUI messes up and makes the UI 2x1 in some places. And it won't let me change the size due to anchoring.

What I'm saying is that I'm not designing it this way, and I can't fix it. NGUI keeps locking the size of my GUI elements to something really tiny (such as 2x1) or something really huge (such as 846354653x864324389), due to anchoring.

And if I try to change the size manually, it sets the offsets of the anchoring to some crazy number, and if I zero those out (because I want it the same size as the parent) it resizes to insanely large numbers. Even if I go to the parent and set the size of the parent to 1280x720. Sometimes I'll get it all configured just the way I want it and then the next time I load the scene it will change all the numbers to something crazy. I don't know what's going on with it. )c:

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OutOfMemoryException: Out of Memory NGUI 3.7.1
« Reply #3 on: September 01, 2014, 02:37:48 PM »
Most obvious reason: Space kit likely uses some camera that happens to draw the UI layer. So when NGUI tries to find the camera that draws the UI, it finds the Space's camera instead of the UI camera.

Check your layers.

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: OutOfMemoryException: Out of Memory NGUI 3.7.1
« Reply #4 on: September 01, 2014, 04:07:27 PM »
The space camera only renders the Space layer (layer 20), but Main Camera was set to render the NGUI layer. Would have have caused the problem?

Here are the render depths for the cameras:

Space (-2) -> Main Camera (-1) -> NGUI Camera (0)

Changing it so that the Main Camera doesn't render the NGUI layer appears to have fixed things. Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OutOfMemoryException: Out of Memory NGUI 3.7.1
« Reply #5 on: September 02, 2014, 11:40:04 AM »
Correct. The UI must only be drawn by one camera, not two.