Search  

UNLOADANDSTOP MISSING TRIANGLEMESH3D

HomeForumsFlash DiscussionunloadandStop missing TriangleMesh3D
Default-profile PV3DFlexer
1 post

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 but thats for

another day; just to let you know opera doesn’t like the loaded papervision flex swf viewport setting to false for autoclipping, it hangs the browser and you

have to click the task bar reference to opera to shunt it into working, chrome failed on the unloadAndStop() not giving back the cpu usage properly from 50

to 32%, which is interesting. 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. Heres Johnny! Again! (But am i getting warm).

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…NO, not in ram.

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

TriangleMesh3D).

I’ve got a strong feeling now this is to do with TriangleMesh3D still being referenced < Flash.Events.EventDispatcher (as3 geom is a converter module that 2

guys developed to convert 3d objects in max to papervision classes (you heard of mr.doob! hes probably a friend of yours too – live long ricardo :)) but i

don’t think its on adobes priority list for flash player 10s unloadAndStop method. Is unloadAndStop(true) missing what the swf has implanted into the main

app/being referenced by the main app?

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?!

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 bitmap 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.

Buddha will bring you goodness.

Pls help me.

My code is as follows:

.............................................. ..............................................

Main App (Interface) Code portion:

<mx:State name=”Car3DScene” enterState=”initSWF(event);” exitState=”unloadSWFHandler(event);”> <mx:Panel id=”mySInnerPanel” width=”100%” height=”100%” styleName=”myPanelStyleMainContainerInner” top=”0” right=”0” bottom=”0” left=”0” paddingTop=”0” paddingRight=”0” paddingBottom=”0” paddingLeft=”0”> <mx:VBox width=”100%” height=”100%” horizontalAlign=”center” verticalAlign=”top” backgroundAlpha=”0”> <mx:HBox width=”100%” height=”100%” borderColor=”#777777” borderThickness=”1” borderStyle=”solid” horizontalAlign=”center” verticalAlign=”middle” backgroundAlpha=”0”> <mx:HBox borderColor=”#1d1d1d” borderThickness=”0” borderStyle=”solid” backgroundAlpha=”0”> <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”/> <![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,false, 0, true); myLoader.addEventListener(Event.UNLOAD,unloadSWFHandler,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: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 (Full Code):

<?xml version=”1.0” encoding=”utf-8”?> <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” preloader=”com.usppro.BasicCustomPreloader” layout=”absolute” backgroundGradientColors=”[#000000, #000000]” backgroundGradientAlphas=”[1.0, 1.0]” backgroundColor=”#000000” width=”625” height=”250” applicationComplete=”init3D();”> <![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 :DisplayObject3D; 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:Canvas width=”625” height=”250” x=”0” y=”0” blendMode=”normal” id=”pv3dCanvas” backgroundColor=”#000000” backgroundAlpha=”1”>

.............................................. ..............................................

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);
    v(-155.177,-26.7364,-45.9812);
    v(108.544,-31.9749,9.2795);
    ...........................
    f(5193,5194,1248,5193,5194,1248);
    f(1248,5195,5196,1248,5195,5196);
}
this.geometry.ready = true;
}

}

Posted about 1 month ago
67126 SaafiDesign
1582 posts
Exclusive author Item was featured Author was featured Referred at least one person Reviewer Sold between 50 000 and 100 000 dollars Bought between 1 and 9 items

?

please leave me alone, I have exams these days :D

Posted about 1 month ago