[Papervision3D] DAE Memory Leak
Ryan Kee
me at ryankee.com
Tue May 5 13:25:39 PDT 2009
Hey everyone. I'm having an issue with a memory leak when dealing with
DAEs. At first I thought it was the same problem that older builds of
PV3D had with dictionary objects not using weak references (Seb fixed
those a few months ago:http://www.sebleedelisle.com/?p=309), but after
running side by side tests of adding and deleting primitives and DAEs,
the memory creep was only present with DAE files.
For my current application I have the need to load and unload several
DAE models and apply the same texture to all of them. In theory,
something like this should work:
Code:
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.view.stats.StatsView;
public var SCENE:Scene3D = new Scene3D();
public var CAMERA:Camera3D = new Camera3D();
public var RENDERER:BasicRenderEngine = new BasicRenderEngine();
public var VIEWPORT:Viewport3D = new Viewport3D(640,480);
public var COLLADA:DAE;
public var MATERIALS:MaterialsList = new MaterialsList();
public var COLOR_MAT:ColorMaterial = new ColorMaterial();
public function init():void
{
//add the viewport to the stage
stage.addChild(VIEWPORT);
//set up material list
MATERIALS.addMaterial(COLOR_MAT, 'TextureName');
//create collada
loadCollada();
//set up mouse event to unload the current dae and load another
stage.addEventListener(MouseEvent.CLICK, unloadCollada);
}
public function loadCollada():void
{
COLLADA = new DAE();
COLLADA.load('dae/yourFileName.dae', MATERIALS);
COLLADA.addEventListener(FileLoadEvent.LOAD_COMPLETE, daeLoaded);
COLLADA.scale = 3500;
}
public function unloadCollada(e:MouseEvent):void
{
//remove the collada from the scene and set everything to null
SCENE.removeChild(COLLADA);
COLLADA.geometry = null;
COLLADA.materials = null;
COLLADA.document = null;
COLLADA = null;
//load the collada again
loadCollada();
}
public function daeLoaded(e:FileLoadEvent):void
{
//remove event listener
COLLADA.removeEventListener(FileLoadEvent.LOAD_COMPLETE, daeLoaded);
//add collada to the scene
SCENE.addChild(COLLADA);
//set up and start render timer
var TIMER:Timer = new Timer(20);
TIMER.addEventListener(TimerEvent.TIMER, renderScene);
TIMER.start();
}
public function renderScene(e:TimerEvent):void
{
RENDERER.renderScene(SCENE, CAMERA, VIEWPORT);
}
If you were to compile this, you'd see that the memory keeps building
every time you click the stage. If I replaced the DAE with a Cube,
there isn't any memory leak. Any ideas?
Ryan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://osflash.org/pipermail/papervision3d_osflash.org/attachments/20090505/ad73caa8/attachment.html>
More information about the Papervision3D
mailing list