Geometrie.dispose() not working?

Software: Away3D 4.x

Avatar
80prozent, Sr. Member
Posted: 14 August 2011 02:10 PM   Total Posts: 430

i am creating a mesh after loading a xml with the meshdata.
everything works fine.
when i try to delete my created mesh i run into problems.

private function clear_scene() : void {
    
if (awayView._view.scene.contains(root_scene_object)) {
     root_scene_object
.dispose(true);
    

if calling the function this error is shown:

Error #1009: Cannot access a property or method of a null object reference. 

i had a look at the funktion and figured that “geometrie.dispose()” and “geometrie.removeSubgeometrie()”
both trying to delete the same subgeometrie in the subGeometrie-Vector.

here are the two functions:

public function dispose() : void
{   
    
var numSubGeoms uint _subGeometries.length;  
    for (var 
uint 0numSubGeoms; ++i)   {
       
var subGeom:SubGeometry _subGeometries.shift();
       
removeSubGeometry(subGeom);
              
subGeom.dispose();
    
}
}

public function removeSubGeometry(subGeometry SubGeometry) : void
  {  

              _subGeometries
.splice(_subGeometries.indexOf(subGeometry), 1);           subGeometry.parentGeometry null;
  
             if (
hasEventListener(GeometryEvent.SUB_GEOMETRY_REMOVED))
                
dispatchEvent(new GeometryEvent(GeometryEvent.SUB_GEOMETRY_REMOVEDsubGeometry));
 
   
invalidateBounds(subGeometry);
  


i changed the dispose() into this:

public function dispose() : void
{   
    
var numSubGeoms uint _subGeometries.length;  
    for (var 
uint 0numSubGeoms; ++i)   {
       
var subGeom:SubGeometry _subGeometries[0];
       
removeSubGeometry(subGeom);
              
subGeom.dispose();
    
}

and no error is shown when calling the function

if my mesh had materials applied i recieved this error when calling dispose() :

index -1 is out of range 

i figured that the error happened in MaterialLibrary.unregisterMaterial():

arcane function unregisterMaterial(material MaterialBase) : void
 { 
  
var id int material.uniqueId;
  
_names[id] null;
  
_materials[id] null;
  
material.setUniqueId(-1);

i changed the function to this:

arcane function unregisterMaterial(material MaterialBase) : void
 {
  
var id int material.uniqueId;
  if(
id!=-1)
   _names[id] 
null;
   
_materials[id] null;}
  material
.setUniqueId(-1);

no error shown anymore.

still after loading and deleting a scene for several times, i recieve the error register overflow

so the dispose function is not clearing buffers on gpu ?

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Avatar
Alexander Seifert, Moderator
Posted: 16 August 2011 09:37 AM   Total Posts: 129   [ # 1 ]

I had problems with disposing materials and geometries (vertex and index buffers), too. I continually created new ones and properly disposed unused ones. However, it seemed like even though the hardware resources should have been cleared, they weren’t and I ran out of everything (as well as registers).

Only then I really backed up a little and finally reworked memory management, which was long overdue, of our game engine, into which Away3D is integrated. Everything is pooled and recycled now. Hardware resources won’t get disposed anymore since they’re shared and constantly reused, which incredibly increased steadiness of memory consumption and overall performance. David Lenaerts’ Blog does have some valuable insights, especially if you’re new to Broomstick / 3D.

Since my background is C++, I didn’t think too much about pooling when laying the foundation of our engine. In C you simply overwrite the new and delete operators, which I realized is not the way to do memory management in AS3 raspberry In general, especially in games when destroying and re-creating enemies and the like, don’t waste a single new operator, it’s incredibly slow in AS3 and a waste of precious time.

Regarding Geometry.dispose(), that indeed is a bug. _subGeometries.shift(); shouldn’t be used anyway to begin with, it’s slow wink

Cheers!
Alex

 Signature 
signature_image

http://www.deltastrike.org

   

Avatar
80prozent, Sr. Member
Posted: 16 August 2011 03:01 PM   Total Posts: 430   [ # 2 ]

thanx for this input.

looks like i need to learn more about memory managment.

 Signature 

sorry…i hope my actionscript is better than my english…

   

Avatar
80prozent, Sr. Member
Posted: 16 August 2011 06:11 PM   Total Posts: 430   [ # 3 ]

@alex:

i gave your statement another thought and have some questions…

can you give me another example about recycling buffer data ?

i want to load a scene, append other scenes, delete all, and load another scene.
how could i recycle data, if i dont know how many meshes will be in a scene?

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Avatar
80prozent, Sr. Member
Posted: 23 August 2011 06:37 PM   Total Posts: 430   [ # 4 ]

hi

does nobody else have issues with geometry.dispose() ?

am i completly wrong and its working ?

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

Avatar
Alexander Seifert, Moderator
Posted: 31 August 2011 10:11 AM   Total Posts: 129   [ # 5 ]

Hey there,

did you get any response yet regarding geometry.dispose()?
Did you file a bug? Is this issue still current?

Concerning memory management:
Basically, what you don’t delete, you don’t need to re-create. In your case with many different scenes being loaded, there may be the case that each scene uses completely different sets of meshes and textures. If so, you’d need to clear a whole scene anyway and free all the memory and resources. However, as mentioned previously, Stage3D doesn’t really do a good job in doing that. If, on the other hand, most resources are going to be reused throughout many scenes, regardless of their quantity, just keep them. Only thing that could happen is that you run out of memory raspberry Then you need to write some nifty logic that sorts out what to keep and what to throw away—granted that Stage3D’s hardware support for freeing resources works.

In general, you need to make a difference between hardware resources and regular memory consumption. HW resources (textures, vertex/index buffers) didn’t seem to be cleared as of beta 1. That may have changed with recent Stage3D updates, haven’t checked yet. If not, that’s a potentially big problem, not just for you.
Regular memory consumption can be controlled by not removing instantiated objects, pooling, resetting and recycling them and not calling unnecessary new operators =)

How’re you doing in general so far?

Cheers!
Alex

 Signature 
signature_image

http://www.deltastrike.org

   

Avatar
80prozent, Sr. Member
Posted: 31 August 2011 02:58 PM   Total Posts: 430   [ # 6 ]

hi
thanks for answer

i didnt fill a bug report yet, cause i thought it make sense to hear from some team members if to report as bug or not…i dont want to be someone reporting bugs that arent bugs.

last time i checked (3 days ago), the issue was still the same…this time i used flash player beta2.

i understand your infos about memory managment and going to keep this in mind….

my c4d to as3 exporter works quite well. i skipped the part of clearing the scene for now, so to clear the scene for now i just refresh my browser.

right now i am working on the import of the c4d stuff, and try to build up a editor thats as close to the c4d functionallity as i can get it.

i still have problems with skeleton animation, but i keep working on all the other stuff, and will go back to skeleton animations once all morph animations work as i want them to.

the morphtag in c4d is a real powerfull tool, allowing you to animate a whole hirarchy of objects (including point morphs and all parameters) by adjusting one slider. i am nearly there, but since some days my dayjob just killst me, i didnt make much progress during the last week. hope that change these days…

maybe this evening i will find the time to make a quick “clean” export of my project and show you.

 

 

 Signature 

sorry…i hope my actionscript is better than my english…

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X