Jump to content

problem with dispose


dav74
 Share

Recommended Posts

Hi,

In the beginning i've a plan and a sphere in a scene. The whole scene disappears after a "sphere.dispose()"

scene.registerBeforeRender(function(){	if (time>0 && flag==1){		if (sphere. intersectsMesh(plan,true)==false){			sphere.position.y=30-0.5*2*Math.pow(time,2);		}		else {			window.setTimeout(function(){				sphere.dispose();				flag=0;			},2000)		}	}	time=time+(1/BABYLON.Tools.GetFps());}); 

thank you for your help

Link to comment
Share on other sites

thank you for your answer

i replaced  sphere.dispose() by scene._toBeDisposed.push(sphere) but nothing change, all my scene disappears after the 2 seconds (not only the sphere)

Link to comment
Share on other sites

I made it work like this : 

scene.registerBeforeRender(function(){    if (time>0 && flag==1){        if (sphere. intersectsMesh(plan,true)==false){           sphere.position.y=30-0.5*2*Math.pow(time,2);    }    else {        window.setTimeout(function(){           if (scene.getMeshByName("sph")){              sphere.dispose();             flag=0;           }        },2000)   }}time=time+(1/BABYLON.Tools.GetFps());}); 

I think the problem comes from the dispose function that is called several times with the same object. 

 

Here are the lines in the Mesh.dispose() method :

var index = this._scene.meshes.indexOf(this);

=> returns -1 if the object does not exists (the method is called several times on the same object), and :

this._scene.meshes.splice(index, 1);

with index = -1 removes the last element of the array (the plane :) )

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...