unloadandStop missing TriangleMesh3D

I am using Flex Builder Pro/Gumbo 4.0 SDK - Flex Project, targeting FP10.

I am using a simple states based model (using enterstate and mouseclick events to execute the loading and unloading of swfs into my main application (aState) at runtime). If i had more time and researched better in the first place i may have invested in a better mvc strategy.

I am loading papervision3d swfs created in flex mxml/as3.

The 3d models i use are made with as3 geom and are classes that extend TriangleMesh3D and use jpg skins using the embed/class technique.

(TriangleMesh3D Inherits from: Vertices3D < DisplayObject3D < DisplayObjectContainer3D < Flash.Events.EventDispatcher).

Hmmm. the latter makes me listen.

As you write your problem you start to work things out, ask better questions, think more clearly - i’m quite inexperienced at programming.

And its Constructor:

TriangleMesh3D (material:MaterialObject3D, vertices:Array, faces:Array, name:String = null, initObject:Object = null)

MaterialObject3D also Inherits from flash.events.EventDispatcher. Ok, so…

…I have managed to load child apps/swfs into the main app using SWFLoader. Testing went well with two browser exceptions (opera and chrome).

However, they all failed on

…The problem: When the swf is unloaded the ram used (lets say 30 mb) stays. As the swfs load and unload without the ram being taken back that ram keeps going up. A ram/gc/listener/referencing/EventDispatcher problem?

Using unloadAndStop(true) sorted out the cpu usage that unload and FP9 were not doing, which is interesting because cpu usage goes to 0 on unloading so are my loaded swfs/references/listeners getting unloaded/killed properly…Well they can’t be.

The garbage collector does not free any of the ram that is used to render the loaded swf (the swf contains 3d data as described above).

The TriangleMesh3D is still being referenced < Flash.Events.EventDispatcher (as3 geom is a converter module that converts 3d objects in max to papervision classes, i don’t think its on adobes priority list for flash player 10s unloadAndStop method.

So Let me just test…

…10 mins later.

Thats interesting i took the 3d as3 geom model away and left the plane with a bitmap on it. When i clicked in and out to load/unload the memory rose to about 250mb then it started to drop and level off at 230 (i am reading the memory through windows task manager), i think unloadAndStop and gc set to true is doing its job(s) but gc took a little time to kick in. It didn’t go back to the original main app weight of about 170mb ram on first load either, which gives me a little concern that there is initial memory leakage or perhaps gc allocates a suitable byte allocation block on the flash player to that level after its loaded up everything?!

Most importantly though the ram stabilised and even came back down a little. So its the 3d model thats the culprit i think!

I’ve tried using the memory profiler in flex to look into this also but cannot get that to work - don’t ask - so i don’t know exactly but its becoming clear
that the 3d model is still being referenced and maybe the skin to.

Can you please help me with this problem.

Help me define it and solve it. What is this problem exactly. Why is UnloadAndStop() not terminating the references/listeners generated by the 3d model on the loaded swf.

Is the loaded swf reversing the referencing logic through EventDispatcher.

How can I terminate the references and from where, which app, main or loaded.

Pls help me.

My code is as follows:


Main App (Interface) Code portion:

<mx:State name=“Car3DScene”
enterState=“initSWF(event);”
exitState=“unloadSWFHandler(event);”>
<mx:AddChild relativeTo="{panel1}" position=“lastChild”>

<mx:Canvas width=“100%” height=“100%”
minHeight=“340” minWidth=“920”
borderColor="#1d1d1d" borderThickness=“1” borderStyle=“solid”
backgroundAlpha=“1” backgroundColor="#000000">
<mx:Image x=“0” y=“0” width=“295” height=“250”
id=“myLogo” source="@Embed(‘assets/images/scene3dMainImage.png’)"
autoLoad=“true” maintainAspectRatio=“false”/>
<mx:Script>
<![CDATA[
import flash.events.*;
import flash.net.URLRequest;
import mx.controls.SWFLoader;
import mx.events.FlexEvent;
import flash.display.Loader;

public var swfContent:MovieClip;

public function initSWF(e:Event):void
{
myLoader.addEventListener(Event.INIT,loadHandler,f alse, 0, true);
myLoader.addEventListener(Event.UNLOAD,unloadSWFHa ndler,false, 0, true);
myLoader.load(“assets/swfs/PV3DCanvasSWFFVPortWR.swf”);
}

private function loadHandler(e:Event):void
{
swfContent = e.target.content;
}

private function unloadSWFHandler(e:Event):void
{
swfContent.loaderInfo.loader.unloadAndStop(true);
//myLoader.unloadAndStop(true);
}
]]>
</mx:Script>
<mx:SWFLoader x=“295” y=“0”
width=“625” height=“250”
minWidth=“625” minHeight=“250”
maintainAspectRatio=“false”
scaleContent=“true” blendMode=“normal”
id=“myLoader” alpha=“1”/>
… …
… …

Here is the code of the incoming SWF:

<?xml version=“1.0” encoding=“utf-8”?>
<mx:Application xmlns:mx=“http://www.adobe.com/2006/mxml
preloader=“com.usppro.BasicCustomPreloader”
layout=“absolute”
applicationComplete=“init3D();”>
<mx:Script>
<![CDATA[
import mx.controls.;
import flash.display.
;
import objects.;//The as3 geom (3d model) classes
import org.papervision3d.cameras.
;
import org.papervision3d.materials.;
import org.papervision3d.materials.special.
;
import org.papervision3d.objects.;
import org.papervision3d.objects.special.
;
import org.papervision3d.render.;
import org.papervision3d.scenes.
;
import org.papervision3d.view.;
import org.papervision3d.objects.primitives.
;
import org.papervision3d.materials.;
import org.papervision3d.view.
;
import org.papervision3d.core.utils.;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.renderables.
;

private var camera :Camera3D;
private var renderer :BasicRenderEngine;
private var scene :Scene3D;
private var viewport :Viewport3D;
private var universe isplayObject3D;

private var c:CarFinal;//The car 3d model class
[Embed(source="/assets/Car_Black.jpg")]
private var CarTexture:Class;

private function init3D():void
{
Application.application.stage.align = StageAlign.TOP_LEFT;
Application.application.stage.scaleMode = StageScaleMode.NO_SCALE;
Application.application.stage.quality = StageQuality.LOW;
Application.application.stage.frameRate = 30;

viewport = new Viewport3D(625,250,false,false,true,true);
pv3dCanvas.rawChildren.addChild(viewport);
pv3dCanvas.rawChildren.addChild(new Stats());
renderer = new BasicRenderEngine();
scene = new Scene3D();
camera = new Camera3D(universe,18,200);
camera.x = 0;
camera.y = 0;
camera.z = -200;
createObjects();
addEventListeners();
}

private function createObjects():void
{
c = new CarFinal();
c.material = new BitmapMaterial(new CarTexture().bitmapData);
c.x = 0;
c.y = 0;
c.z = 0;

universe = new DisplayObject3D();
universe.addChild©;

scene.addChild(universe);
universe.x = 200000;
universe.y = -200000;
universe.rotationY = -90;
camera.target = universe;
}

private function addEventListeners():void
{
addEventListener(Event.ENTER_FRAME, loop3D,false,0,true);
}

public function loop3D(e:Event):void
{
camera.target.x -= (((mouseX - (pv3dCanvas.width * 0.5)) * 12) + camera.target.x) / 24;
camera.target.y -= (((mouseY - (pv3dCanvas.height * 0.5)) * 12) + camera.target.y) / 24;

universe.yaw(-0.6);

renderer.renderScene(scene, camera, viewport);
}
]]>
</mx:Script>
<mx:Canvas width=“625” height=“250”
x=“0” y=“0”
blendMode=“normal”
id=“pv3dCanvas”
backgroundColor="#000000" backgroundAlpha=“1”>
</mx:Canvas>
</mx:Application>


Here is a code portion of the 3d car model class

package objects
{
import org.papervision3d.core.;
import org.papervision3d.core.geom.
;
import org.papervision3d.core.geom.renderables.Triangle3D ;
import org.papervision3d.core.geom.renderables.Vertex3D;
import org.papervision3d.core.math.NumberUV;
import org.papervision3d.core.proto.*;

public class CarFinal extends TriangleMesh3D
{

public var verts :Array;
public var faceAr:Array;
public var uvs :Array;

private function v(x:Number,y:Number,z:Number):void
{
verts.push(new Vertex3D(x,y,z));
}

private function uv(u:Number,v:Number):void
{
uvs.push(new NumberUV(u,v));
}

private function f(vn0:int, vn1:int, vn2:int, uvn0:int, uvn1:int,uvn2:int):void
{
faceAr.push( new Triangle3D( this, [verts[vn0],verts[vn1],verts[vn2] ], null, [uvs[uvn0],uvs[uvn1],uvs[uvn2]] ) );
}

public function cobraCarFinal( material:MaterialObject3D=null, initObject:Object=null )
{
super( material, new Array(), new Array(), null );
verts = this.geometry.vertices;
faceAr= this.geometry.faces;
uvs =new Array();
v(108.544,-31.9748,-101.242);

f(1248,5195,5196,1248,5195,5196);
this.geometry.ready = true;
}

}

}