Hans Posted March 3, 2017 Share Posted March 3, 2017 Hi @all again, I have a question: I want to remove a bulletMesh (bullet) with the dispose function if it collide with something like bullet.physicsImpostor.onCollideEvent = function (self, other) { console.log(self, other, self.position); self.object.dispose(); }; Got an Error: Uncaught TypeError: Cannot read property '_wakeUpAfterNarrowphase' of undefined at World.internalStep (cannon.js:13514) at World.step (cannon.js:13211) at CannonJSPlugin.executeStep (babylon.max.js:45178) at PhysicsEngine._step (babylon.max.js:36315) at Scene.render (babylon.max.js:21270) at main.js:847 at Engine._renderLoop (babylon.max.js:8509) What do I wrong? Ho can I do this? Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 3, 2017 Share Posted March 3, 2017 that's interesting! Seems like something is not being disposed correctly. Could you wrap the dispose function in a setTimeout() ? Is self.object referring to the mesh? And if you can recreate it on the plyground it would be great! Steffen 1 Quote Link to comment Share on other sites More sharing options...
Hans Posted March 3, 2017 Author Share Posted March 3, 2017 4 hours ago, RaananW said: Could you wrap the dispose function in a setTimeout() ? Is self.object referring to the mesh? Dont know how to understand this, but here is the BG: http://www.babylonjs-playground.com/#1GPEKY Quote Link to comment Share on other sites More sharing options...
Temechon Posted March 4, 2017 Share Posted March 4, 2017 @RaananW It works with a setTimeout : http://www.babylonjs-playground.com/#1GPEKY#2 The exception seems to be in cannon though... Below the code where the exception happen N=2 and bodies.length=1 (here as well: https://github.com/BabylonJS/Babylon.js/blob/master/dist/cannon.js#L13512) // Wake up bodies for(i=0; i!==N; i++){ var bi = bodies[i]; if(bi._wakeUpAfterNarrowphase){ bi.wakeUp(); bi._wakeUpAfterNarrowphase = false; } } Hans 1 Quote Link to comment Share on other sites More sharing options...
Hans Posted March 5, 2017 Author Share Posted March 5, 2017 It takes a while to fix that right? Let me know if it is fixed. Quote Link to comment Share on other sites More sharing options...
Temechon Posted March 5, 2017 Share Posted March 5, 2017 It's between the magic hands of @RaananW, the physic-master, so let's wait for him. Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 6, 2017 Share Posted March 6, 2017 Well... Seems like we need to play with cannon a bit An array is being manipulated while it is being changed, so it seems. Again, the quickest solution would be to wrap this in a setTimeout (thanks @Temechon ). The problem is the cannon loop which doesn't update this N variable (the number of objects). So, disposing on the beginning of the next frame works. And without manipulating cannon, this seems to be the only solution possible. I can add a setTimeout for the dispose function, that however might cause an interesting issue with the current frame - the physics body will still be there till the end of the frame, until you call dispose. If this is an accepted solution (again, seems to be the only one at the moment), I will add that. Quote Link to comment Share on other sites More sharing options...
Hans Posted March 6, 2017 Author Share Posted March 6, 2017 A late dispose works, but is not fashionable. In my case I can see how the bullet continue fly a bit longer after it collides. One scond is also realy long. I want the possibility to choose my own setTimeout value. So I think dont change the state. 11 hours ago, RaananW said: And without manipulating cannon, this seems to be the only solution possible Why we can't change cannon? Maybe it is a nice idea to contact the cannon developer or/and make a fork or something like this. I Think an own cannon developed by the babylon.js community will be nice. This prevents that the physics becomes a development bottleneck. Besides the cannon developer seems inactive for more than one year. I just brainstorming. Quote Link to comment Share on other sites More sharing options...
RaananW Posted March 6, 2017 Share Posted March 6, 2017 I have already contributed to cannon, this is of course possible. The problem is - how long will it take, and whats need to be done. In this case - the N variable was implemented like that for performance reasons. setTimeout without time value will execute before the next frame starts. it won't be a second, and not half a second. it will be one frame after. I do agree it is not the best solution but it is A solution, and it works, without making major changes. 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.