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.
Cleaning up a view3DSoftware: Away3D 4.x |
||
|
||
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? 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! 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. |
||
|
||
|
||
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. |
||
|