Author Topic: Shader3D material not working for second time  (Read 129 times)

Kumar Swamy Vishnubhatla   «   on: August 08, 2012, 03:46:52 AM »
Hi,

Here Is my following example code:

var mWallMaterial_1 : Shader3D;
var iWallTexture_1 : Texture3D = scene.addTextureFromFile("yellowbork.png");
var fWallFilter:TextureFilter = new TextureFilter(iWallTexture_1);
         
mWallMaterial_1 = new Shader3D("wall");
mWallMaterial_1.filters.push(fWallFilter);
mWallMaterial_1.build();

//creating cube first time
var t_oWall:Cube  = new Cube("walls", 50, 50, 50, 4, material);
oObjects.addChild(oWall);
oWall.setMaterial(mWallMaterial_1); //working fine
//adding delay here
TweenMax.delayedCall(3, fRemoeItAddOneOther);
private function fRemoeItAddOneOther() : void
{
    oObjects.dispose();
         
    var oWall_1 : Cube  = new Cube("walls", 50, 50, 50, 4);
    oContainer.addChild(oWall_1);
    oWall_1.setMaterial(mWallMaterial_1); //not working
}

Here my doubt is why it's not working second time? after disposing first material applied object, again if you create another new object and apply same material not working! why?

anybody can help me about it??

thanks!

Ivan Vodopiviz   «   Reply #1 on: August 08, 2012, 12:55:02 PM »
Hi,

The problem is that when you call dispose() in your object, it also disposes any materials attached to it. Just so you know, you only need to call dispose() when you really need to get rid of those objects. In any other case, removeing them from the scene is enough.

Cheers,

Sam Chau   «   Reply #2 on: August 09, 2012, 08:13:44 AM »
Hi Ivan,

Does that mean that if two different ojbects share the same material/texture, and then I dispose one of the objects, the material is no longer available? I get a null object error after Texture3D.upload() is called.

Ivan Vodopiviz   «   Reply #3 on: August 09, 2012, 09:55:23 AM »
Exactly, they share the material. Again, unless you have specific reasons to do it, I'd avoid calling dispose() by hand.

Regards,