Proper setup and teardown for a View3D

Software: Away3D 4.x

Backov, Newbie
Posted: 20 June 2012 06:09 PM   Total Posts: 4

I am using Away3D 4..

So my setup code lives in the createChildren() method of a UIComponent. I’ve tested, and it’s only ever run once per UIComponent in this setup. The spark.View it lives in is destroyed and so this component is created every time the user goes to the game view.

_view = new View3D();
    
_view.backgroundColor 0xff0000;
    
_view.width this.width;
    
_view.height this.height;
    
addChild(_view);
 
    
    
_view.camera.lens = new OrthographicLens(_view.height);
 
    var 
mat:Matrix3D = new Matrix3D();
    
mat.appendTranslation(_view.width/2,-_view.height/2,0);
    
mat.appendScale(1,-1,1);
    
_view.camera.transform.append(mat); 

Basically I’m moving the origin of the ortho projection to the top left and flipping the y (using it for 2d).

Now this works great - ONCE.

If I don’t do any disposing, I get multiple copies of this with the added objects until it bombs out with “too many stage3d…” error.

If I dispose between views, I never get the too many stage3d errors, but none of the added objects are visible (only the red background.)

How can I debug this? It seems some state is being held onto despite the fact that I am disposing.

   

Richard Olsson, Administrator
Posted: 20 June 2012 06:42 PM   Total Posts: 1192   [ # 1 ]

I’m not sure I understand the problem exactly. Is everything working fine the first time you run the View component? On the second run, are you re-creating everything (the entire scene graph et c)? If you don’t want to do that, save the Scene3D instance (_view.scene) somewhere central and reassign it to the new View3D instance that gets created once the component is revisited.

   

Backov, Newbie
Posted: 20 June 2012 06:56 PM   Total Posts: 4   [ # 2 ]

Sorry, getting the hang of this forum software. Preview seems to post. smile

Richard Olsson - 20 June 2012 06:42 PM

I’m not sure I understand the problem exactly. Is everything working fine the first time you run the View component?

Yes. smile

On the second run, are you re-creating everything (the entire scene graph et c)?

Yes, in this case the scene graph is (in a minimal case) two Sprite3Ds, and it is being recreated.

var bgSp:Sprite3D = new Sprite3D(getBGTextureTest(), _view.width,_view.height);
    
_view.scene.addChild(bgSp);
    
    
bgSp.moveTo(_view.width/2_view.height/2,BACKGROUND_Z);
    
    
// Get board rect
    
    
var boardSP:Sprite3D = new Sprite3D(getBGTextureTest(0xffff0000), _view.width_view.height*_boardHeight);
    
_view.scene.addChild(boardSP);
    
    var 
posY:int = (_view.height*_boardHeight/2) + _view.height*_boardY;
    
    
boardSP.moveTo(_view.width/2,posY,BOARD_BACKGROUND_Z); 

So not a huge effort to recreate. The origin of the Sprite3Ds not being in the top left is a little annoying, but other than that it works.

I just tried to save the scene in a static and just reuse it, same result - red screen on the second try, assigning the scene in the constructor of the view3d. Saving the scene really seems like an optimization though - I don’t mind recreating it for now as long as I can get the view creating cleanly (which I don’t seem able to do.)

   

Richard Olsson, Administrator
Posted: 20 June 2012 07:02 PM   Total Posts: 1192   [ # 3 ]

I still don’t understand. To which of my questions are you answering yes? smile

   

Backov, Newbie
Posted: 20 June 2012 07:06 PM   Total Posts: 4   [ # 4 ]

Hope that’s clearer. smile

Thanks for the help on this by the way.

   

Backov, Newbie
Posted: 21 June 2012 05:00 PM   Total Posts: 4   [ # 5 ]

I’ve been trying to debug this issue some more, still stymied. Some more facts:

Recycling the view works - if I store it in a static and recreate the scene, camera, etc - that works. It’s horrible though and I don’t want to do it.

The camera matrix is the same between creations.

The sprites are invisible, but the AwayStats panel shows the same amount of polies for every invocation, visible or not.

I’ve tried pulling the camera back, I’ve tried paranoia “lookat” to make sure the camera or the sprite didn’t move off.. Something weird is happening.

Creating a new view and having it work after the first one is pretty basic - can someone at least give me some paths to go down to troubleshoot this?

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X