Author Topic: UIScrollView, UITable, UITexture, Memory Crash  (Read 3047 times)

heizenrader

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
UIScrollView, UITable, UITexture, Memory Crash
« on: January 05, 2015, 10:07:47 PM »
Hi,

I'm pulling a list of textures from the web and attaching them to UITextures in a scrolling table.  I'm running into an issue with memory.  So I essentially went the route of Destroying the texture from non-visible cells.  This works, but is terribly slow and feels glitchy.

My current system relies on each cell having .onDrag being set.  This calls a function that loops through and removes textures from non-visible children.  For visible children it ques up a network request (with cacheing) and re-applies the texture. 

I know this is horribly inefficient.  I've looked into ditching this route and applying a "UIWrapContent" script but this seems to be used only with ScrollViews and I cannot figure out how I can put in "Y" spacing between the cells like I can with a table.   The other option was to attach a script or something to the child Widget / UITexture that would notify me when it becomes visible/non-visible.   This would cut down on the amount of iterations required on each child when scrolling.  I also noticed tables have a .onReposition delegate.  But I believe I'm misunderstanding its use as I've not been able to get it working.  Any attempts to  EventDelegate.Add(table.onReposition, myFunction) fail. 

Any help would be greatly appreciated. 

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView, UITable, UITexture, Memory Crash
« Reply #1 on: January 06, 2015, 10:58:50 AM »
Wrap content script is like a grid. You specify the cell size and it will do the rest. If your content is 100 pixels and you want 20 pixels of padding, then use cell size of 120.

That said, I'm not clear on why you need to do this. What memory issues are you running into? How large are the textures? How many of them do you have?

UITable.onReposition is a C# delegate, not an NGUI delegate. You add to it via += like so: table.onReposition += MyFunction;

heizenrader

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIScrollView, UITable, UITexture, Memory Crash
« Reply #2 on: January 06, 2015, 02:13:22 PM »
So far there are 80-120 PNG (1201x520) images.  A sample image is sized at around 154 KB.   If I tried to load them async through a network plugin the app would eventually crash with an out of memory warning.  The only way to avoid this was to remove the texture from the cell - prefab and load it back in when it became visible.  I just couldn't figure out an effective way to remove them upon the cell becoming visible/hidden.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView, UITable, UITexture, Memory Crash
« Reply #3 on: January 07, 2015, 01:15:16 PM »
Sample image size on the disk is completely irrelevant. 1201x520 PNGs have 4 channels (RGBA), so 1201*520*4=2,685,280 bytes each when uploaded to the videocard. More if you use mip-mapping. This is indeed a lot.

heizenrader

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIScrollView, UITable, UITexture, Memory Crash
« Reply #4 on: January 07, 2015, 04:11:46 PM »
Do you have any suggestions on a better way to play this out?  Or do you know of a way to track individual rows/cells becoming visible so that I do not have to loop through every single object checking visibility through the onDrag of the objects?

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView, UITable, UITexture, Memory Crash
« Reply #5 on: January 08, 2015, 08:36:21 AM »
All widgets have an "isVisible" flag. With culling enabled on the scroll view's panel this flag will be set to 'false' when the widget is not visible.

heizenrader

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIScrollView, UITable, UITexture, Memory Crash
« Reply #6 on: January 12, 2015, 11:31:18 AM »
Sorry, to keep this thread alive.  Thanks for the help so far.  I'm still trying to figure out the best way to be notified of the  .isVisible property on the widget.   I have a scrollview > table.   I currently loop through all widgets in the table in the .onDrag method which is horribly inefficien.  Is there a better solution to this? (I.E. delegate method of when a widget changes state?)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIScrollView, UITable, UITexture, Memory Crash
« Reply #7 on: January 13, 2015, 03:12:35 PM »
Assuming you cache your list of widgets, it should be pretty efficient. It's only if you retrieve a new list of widgets that it becomes inefficient. The "isVisible" flag checks several things, so nope, there is no delegate for it.