Cleaning up a view3D

Software: Away3D 4.x

ASWC, Member
Posted: 24 April 2012 10:38 PM   Total Posts: 76

What is the proper way of removing everything from a View3D in order to load a new level into it? So far all my attempts have failed and after loading 3 or 4 levels I run into the infamous Flash error ‘cannot create texture’ (running out of memory). I got to say a simple view3D.clear() would be quite useful.

   

ASWC, Member
Posted: 25 April 2012 04:30 PM   Total Posts: 76   [ # 1 ]

Hum ... such a very important subject, cleaning up, and no answer so far. Is there no way in Away3D 4 to clean up memory and keep uploading to the same Context3D?
If I use the same view3D I can load 4, 5 levels before running out of memory on the same Context3D.
If I call view.dispose() I get a bunch of error after loading 4, 5 levels (can be same level or other levels doesn’t matter) making me think that view.dispose() is not requesting a new context3D anyway.
If I create a new view3D then weirdly enough I run out of Stage3D after loading 5 levels since Away3D uses the next available Stage3D but never go back to a previous one big surprise

So I need either to force the creation of a new Context3D or unload everything that was loaded in the current Context3D or be able to create new view3Ds and force Away3D to use Stage3Ds that were used before.

   

ASWC, Member
Posted: 25 April 2012 07:47 PM   Total Posts: 76   [ # 2 ]

My working fix so far has been to use a view until I get some createTexture errors from the Context3D at which point I create a new View3D and move on. Eventually I run out of Stage3D instances but I’m still able to load in between 20 to 25 levels.

Trying to reset one View3D (and its one Stage3D instance) is not working so far but I’ll keep tweaking Away3D code and see what I can get.

Calling view.dispose() succeeds only in releasing the Stage3D but the view itself becomes useless and can’t display anything anymore. Two solutions here:

Resetting the View3D so you can load a new level in it after a call to dispose(). (Tweaking Away3D code but no success so far)

Create a new View3D but reset correctly its Stage3D instance so it doesn’t fail at displaying objects that it did load and display before.

Ultimately I think I’ll try to manage myself the Stage3D instances and clean them up correctly and then pass them as parameter in the View3D since Away3D is apparently not able to do it.

Any light or advice from the Away3D team would be quite welcome.

   

Waffles, Newbie
Posted: 25 April 2012 09:03 PM   Total Posts: 3   [ # 3 ]

I’m still new to Away3D, but something I learned from working with the Starling framework from others, is that once a texture is created in memory, it’s there until the app is quit.  From what I recall, there’s no way to remove it manually—or easily?—it’s up to the system to clean it up.

So for example, if you create a 2k texture in memory at launch, then later replace its bitmap data with a .5k image as example, it’s still taking up 2k in memory.

What you’ll want to do, is only create so many textures up front and reuse them where ever possible; so when going to a new level, take the pooled textures from the prior level and repurpose them for the new one.

This will eliminate the texture error you’re getting later on and it’s good practice, because then you determine up front how much memory your project will need.

Do you have any kind of profiler program you’re running?  If not, even a monitor app that can show you how much VRAM you’re using can make a big difference.

I use a program called atMonitor on my Mac, which tells me how much VRAM I’ve used, GPU usage, and so on.  Prior to using this, I had no idea that one of my early Starling projects was using up all available VRAM after simply going into a new section.  After seeing it, I restructured my entire project to use the same textures over and over and now I never exceed 20% of my available VRAM.

Anyways, if my ramble makes sense, reusing textures is key and it’s a good idea regardless, since there are so many variants on VRAM size.

   

ASWC, Member
Posted: 25 April 2012 10:46 PM   Total Posts: 76   [ # 4 ]

Thx for posting. What you say makes sense but if we can’t create multiple levels for a game then the whole FP11 deal becomes a big joke. I even don’t see why Adobe would even bother publishing it. More likely there’s a way to clean up and start over so we can load a virtually infinite number of levels just like modern 3D games do: load a level, unload a level, load the next one and so on.

   

Waffles, Newbie
Posted: 25 April 2012 11:28 PM   Total Posts: 3   [ # 5 ]

This isn’t a limitation of FP 11, it’s a limitation of available VRAM of the system.  Once you create a texture in memory, it occupies that space until the system cleans it up.  This is something you’ll have to deal with when working with any platform, not just Flash.

You can pretty much create as many levels as you like, you just need to manage your assets and take into account that VRAM is a limited resource.

You only have so much to work with, so there’s only so many textures that can be created in memory before a particular system runs out, and this of course varies between them—my Mac as example has 512 where as my PC has 3 gigs.

So to hopefully to be a bit more clear,  when I say reuse textures, I don’t mean reuse the same image over and over, I mean reuse the texture space.

So store your images(BitmapData) in an array as an example, since the CPU has full access to the system ram along with virtual memory, then when going to a new level, you use that data to replace the bitmap data that’s in the textures you’ve already established in memory; which of course you can take and apply to different meshes and so on.  This way no new texture space is created.

For reference, a blank 512x512 texture takes up as much space in VRAM as a 512x512 texture with an image in it from what I learned; and as noted above once that texture is created, it continues to occupy memory until it’s written over from what I recall.

And I don’t know if there’s a built in class for SpriteSheets with Away3D, but if there is, this is another way to help manage memory.

Anyways, you’re not limited with FP11, you just have to know how to work with the limitations of the system, if any of my rambles make sense? :O

   

ASWC, Member
Posted: 26 April 2012 06:18 AM   Total Posts: 76   [ # 6 ]

Yes this is not what I’m talking about I’m afraid. I’m talking about the memory used in GPU by the Context3D which is virtually limited to 128M for each Context3D instances. When I create a level and render it in a Stage3D instance, all my textures, vertices and so on are loaded in memory in the GPU and then my level is rendered and updated. If I load more levels into the same Context3D, once I reach the allocated memory limit the uploading of texture in that Context3D will fail. At this point I can move on to the next Stage3D instance and use its fresh Context3D to keep going but then once I run out of Stage3D instances I can’t load any new levels. Like I said before I can do that for about 20 to 25 levels. The Flash docs make it clear that there’s a way to request a new Context3D for each Stage3D instances but Away3D doesn’t provide me with a way to do it. There should be a view.destroy() or something like that. That’s what I’m trying to implement and if I succeed I will share my results. I see that there has been other posts on that subject but the Away3D team has never participated in them which makes me think they have no answers and no solutions to this problem. So we are on our own on this one.

   

ASWC, Member
Posted: 26 April 2012 06:14 PM   Total Posts: 76   [ # 7 ]

Success! Finally done it and I can now load an infinite number of levels!
I’m suspecting some bugs/inconsistencies in the Away3D framework that makes this process quite difficult and painful. Could also be the way Context3D works that makes it difficult but from what I’ve seen it really looks like it’s Away3D. Here’s what I’ve done:

Modified view.dispose() so instead of simply removing everything and making the view useless it resets the Stage3D instance and forces it to acquire a new Context3D. The view dispatches an event for when the new Context3D is available to indicate when the view is ready to be used again.

The way Away3D works right now it forces you to get rid of that view3d since it no longer can access a Stage3D. If you call dispose on it and create a new view3d that new view3d will get the same Stage3D but in my testings that Stage3D instance is not properly cleaned and I still run into issues after loading 4/5 levels. That’s why I modified the view.dispose().

Now, I cleaned my view and keep working with it. That view is still working with the same Stage3D which has a new Context3D. Seems like I can just reload everything in it except that I can’t and that’s where I think Away3D has some problems. If I just reload the same level I find out that the only objects that show are the skybox and ground. All other objects have their geometry loaded but no texture. To force those objects to show up, all lights, shadow, methods and so on have to be recreated new (if you kept a DirectionalLight instance and use it for loading the same level the objects won’t show up). For ex: If you have a cached model that was used in a level before it won’t show up. But you can’t use model.clone() either it doesn’t work!. The solution is to use your cached model/meshes and clone their geometry in a fresh new mesh and pass a freshly created material and booya you got to load a new level and you can do this for as long as you want.

The reason I suspect a Away3D problem on this is because for some reason the skybox and any ground are not affected by this. You can pass the same skybox and the same ground you used before in a level and they still show up. Any other object type don’t.

   

Jon, Newbie
Posted: 03 May 2012 08:45 AM   Total Posts: 7   [ # 8 ]

Hi !

Could you share you modified View3D Class ?

Thanks a lot !

   

itosto, Newbie
Posted: 17 May 2012 04:21 PM   Total Posts: 1   [ # 9 ]

Hi ASWC:

I am working with the same issue. It would be wonderful if you would share this View3d class with us.

Thanks!

   

ASWC, Member
Posted: 17 May 2012 04:46 PM   Total Posts: 76   [ # 10 ]

I did run into additional issues since everything was working correctly on my computer but not on my colleagues’ computers. I’m in the process of trying to improve everything so that my project works on all compatible computers. I’ll let you know when I found a stable solution.

   

ASWC, Member
Posted: 19 May 2012 03:27 PM   Total Posts: 76   [ # 11 ]

Alright I was about to case test again this issue to find a stable solution so I started by downloading the latest away3D which apparently was updated 10 days ago.
Starting by simply disposing the view and recreating a new one which made me run out of stage3D instances rapidly in my previous experience. Except that it doesn’t anymore. Did I miss something in my prior tests or was this addressed in this new version? Anyway to clean a view (at least with this latest version) simply call dispose() on it. Then recreate a new view3D and use it as normal. It really seems very different from what I had before since by doing that you always work with the first stage3D instance instead of looping through all of them and then getting a out of stage3D instances error.
I know on my system I get 5 stage3D instances to work with and I was able to dispose and create new view3Ds 20 times in a row. Also I checked the Away3D code and every call to view3D.dispose() do dispose as well the context3D which should truly free all memory associated with whatever you loaded before.  So it seems that issue is not only resolved but is truly simple to use. (was it always simple and I didn’t test it correctly or is it fixed now in the new version? idk)

   

Jon, Newbie
Posted: 17 June 2012 10:39 AM   Total Posts: 7   [ # 12 ]

Thank you for your answers.

I don’t think your tests were wrong but that the new version fixed that (didn’t tested it yet) wink

Hope it works !

Cheers.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X