dav74 Posted December 8, 2013 Share Posted December 8, 2013 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 8, 2013 Share Posted December 8, 2013 It could be related to setTimeout which can update the list of meshes during a render Could you try with scene._toBeDisposed.push(sphere) ? Quote Link to comment Share on other sites More sharing options...
dav74 Posted December 8, 2013 Author Share Posted December 8, 2013 thank you for your answeri replaced sphere.dispose() by scene._toBeDisposed.push(sphere) but nothing change, all my scene disappears after the 2 seconds (not only the sphere) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 8, 2013 Share Posted December 8, 2013 Could you share a jsfiddle with your bug? Quote Link to comment Share on other sites More sharing options...
dav74 Posted December 8, 2013 Author Share Posted December 8, 2013 it's done : http://jsfiddle.net/dav74130/N8ZR6/ Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 9, 2013 Share Posted December 9, 2013 Your jsfiddle seems incomplete (no html and no external reference to babylon.js) Quote Link to comment Share on other sites More sharing options...
Temechon Posted December 9, 2013 Share Posted December 9, 2013 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 ) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 9, 2013 Share Posted December 9, 2013 this should work too:window.setTimeout(function(){ if (scene.getMeshByName("sph")){ sphere.dispose();}},2000)flag=0; // Moving flag out of timeout function Quote Link to comment Share on other sites More sharing options...
dav74 Posted December 9, 2013 Author Share Posted December 9, 2013 @Temechon,@DeltakoshThank you for your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.