Objects sharing the same material cause Error when disposed

Software: Away3D 4.x

Avatar
FlyOn, Jr. Member
Posted: 09 December 2011 01:07 PM   Total Posts: 36

Bug or bad practice?

var colorMaterial:ColorMaterial = new ColorMaterial(0xff00ff);
var 
container:ObjectContainer3D = new ObjectContainer3D();
var 
sphere:Sphere = new Sphere(colorMaterial);
var 
sphere2:Sphere = new Sphere(colorMaterial);
container.addChild(sphere);
container.addChild(sphere2);
_view.scene.addChild(container);
container.dispose(true); 

when the container starts disposing the seccond sphere, the material of the seccond sphere is already disposed, which causes an error:

RangeErrorError #1125: The index -1 is out of range 1.
 
at away3d.materials::MaterialLibrary/unregisterMaterial()[D:\1WEBDESIGN\Projects\DaVine\lib\away3d\materials\MaterialLibrary.as:107]
 at away3d
.materials::MaterialBase/dispose()[D:\1WEBDESIGN\Projects\DaVine\lib\away3d\materials\MaterialBase.as:165]
 at away3d
.entities::Mesh/dispose()[D:\1WEBDESIGN\Projects\DaVine\lib\away3d\entities\Mesh.as:166]
 at away3d
.containers::ObjectContainer3D/dispose()[D:\1WEBDESIGN\Projects\DaVine\lib\away3d\containers\ObjectContainer3D.as:618]
 at BugTest
()[D:\1WEBDESIGN\Projects\DaVine\src\BugTest.as:29] 
   

John Brookes, Moderator
Posted: 09 December 2011 02:45 PM   Total Posts: 732   [ # 1 ]

Its always done it :(


From a quick random guess
Only tested with the most basic setup (what you posted) and a bit of profiling

In MaterialLibrary.as
unregisterMaterial function

...
if (
material.owners.length == 0//<-added this
 
material.setUniqueId(-1);

 

and
In Mesh.as dispose

...
if (
deep{
 _geometry
.dispose();

 if (
_material{
  _material
.dispose(true);
  
material null;
 
}
 
if (parentparent.removeChild(this); //<added this

NO idea what happens with cloned mesh or other stuff didnt test.
But the colomaterial sphere geom and subg gets gcd.

   

Avatar
FlyOn, Jr. Member
Posted: 10 December 2011 12:06 PM   Total Posts: 36   [ # 2 ]

thanks! this works for me for now .. will post a github issue about it though.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X