material deep dispose error

Software: Away3D 4.x

Zerone, Newbie
Posted: 20 October 2011 11:20 PM   Total Posts: 22

When I want to clean the mesh item, I will also clean the mesh’s material for memory issue.

So I use:
meshItem.material.dispose(true);  // deep clean

But some time I got error like:
RangeError: Error #1125: The index -1 is out of range 31.
in away3d/materials/MaterialLibrary.as:107]

my fix is:
update the “unregisterMaterial” and “unsetName” as below

/**
   * Removes a material from the library when created. Called by MaterialBase.
   * @private
   */
  
arcane function unregisterMaterial(material : MaterialBase) : void
  {
   
var id : int = material.uniqueId;
   if( 
id >= 0 && id < _names.length ){ _names[id] = null; }
   
if( id >= 0 && id < _materials.length ){ _materials[id] = null; }
   material
.setUniqueId(-1);
  
}

  
/**
   * Releases a material's name.
   * @private
   */
  
arcane function unsetName(material : MaterialBase) : void
  {
   
var id : int = material.uniqueId;
   if( 
id >= 0 && id < _names.length ){
    _names[id] 
= null;
    
delete _names[id];
   
}
  } 

also change “BasicDiffuseMethod.as”

override public function dispose(deep : Boolean) : void
  {
   
if (_texture) {
    BitmapDataTextureCache
.getInstance().freeTexture(_texture, deep);
    
_texture = null;
   
}
  } 

and “BitmapDataTextureCache.as”

public function freeTexture(texture : Texture3DProxy, deep : Boolean = false) : void
  {
   _usages[texture]
--;
   if (
_usages[texture] == 0) {
    _textures[Texture3DProxy
(texture).bitmapData] = null;
    
texture.dispose(deep);
   
}
  } 

hope this help

   

Richard Olsson, Administrator
Posted: 21 October 2011 07:06 AM   Total Posts: 1192   [ # 1 ]

Thank you. This will no longer be a problem after the texture refactor that is just now brewing in the “texturerefactor” branch on GitHub. This will essentially leave all memory management to you (the user) so there will no longer be a need to “deeply” dispose anything.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X