Found somethig wierd…

Software: Away3D 4.x

sargon, Member
Posted: 12 February 2012 09:21 PM   Total Posts: 51

Hi i have found somethig wierd in Geometry.as line 141,
there is a loop which dispose subGeometries:

public function dispose() : void
{
 
var numSubGeoms uint _subGeometries.length;

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

I wonder that subGeom in loop should be:

var subGeom:SubGeometry _subGeometries[i]

or am I wrong ?

not 0 but i…

   

Avatar
Apprentice, Jr. Member
Posted: 13 February 2012 08:10 AM   Total Posts: 45   [ # 1 ]

I don’t think this is an error. If you look inside the function removeSubGeometry, you see:
_subGeometries.splice(_subGeometries.indexOf(subGeometry), 1);
which removes the subgeometry from the subgeometries list.

So if A, B and C are geometries in the subgeometries list: [A, B, C]
Then the dispose function removes the first element from the list 3 times, so you per loop you get: [A, B, C] -> [B, C] -> [C] -> []
So it looks alright to me.

(Although I do wonder if perhaps it’s faster to remove the last element of the list, depending on how the .splice function works, maybe it has to move all elements after the element that’s been deleted)

—Apprentice

   

sargon, Member
Posted: 13 February 2012 06:03 PM   Total Posts: 51   [ # 2 ]

oh yes you are right, didnt saw that.

but mayby

while(_subGeometries.length)
{
 removeSubGeometry
(_subGeometries[_subGeometries.length-1]); //without splicing _subGeometries
_subGeometries[_subGeometries.length-1].dispose();
_subGeometries.pop();

would be the fastest way?

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X