[Resolved] physics.stop() cannot be called when the world is locked and in the middle of number crunching

I just want to get rid of the old world I have while transitioning to the next one, but I can’t call physics.stop()?

I do have about 7 object:addEventListener(“collision”, object);

and I tried to add object:removeEventListener(“collision”, object) for all of them but it still doesn’t execute physics.stop()

I even tried physics.pause() before physics.stop() but to no avail.

How can I destroy the world as a whole with one command?

Thanks,
Lucky [import]uid: 49300 topic_id: 28216 reply_id: 328216[/import]

Have you tried creating a new display group, inserting everything from the world in that group and then removeSelf() and nil? [import]uid: 77199 topic_id: 28216 reply_id: 114000[/import]

Hmm… I’ll try that. I’d figure changing scenes would do that automatically removing objects and stuff.

Are you talking about images or physic bodies? [import]uid: 49300 topic_id: 28216 reply_id: 114003[/import]

Yeah I just tried it. I already had LAYER display groups and removed all of them when exiting scene. It does not work

P.S. player_object collides with an sensor named “enter” [import]uid: 49300 topic_id: 28216 reply_id: 114004[/import]

Can you provide a little more information? Do you have some kinda game where the screen is always moving and after they complete a stage you want it to automatically delete the first stage and go into the second stage directly?

What are you trying to achieve exactly with physics.stop? [import]uid: 77199 topic_id: 28216 reply_id: 114006[/import]

Just a simple game with buildings and if the player_object (just a small circle physic body) went behind the building (has a sensor) then the building would use a collision function to go transparent. There is also an enter sensor collision in front of the door. And when the player_object hits that enter sensor collision it would

[lua]storyboard.gotoScene(“building”, “fade”, 500);[/lua]
So when the player enters the building there would be a new physics world with new objects to have the same transparency collision. Same for when he goes back outside. Should physics.stop() be used when going to a new scene with new physic bodies? Or…?

Yeah but that’s what I want to achieve. Next scene, new physic bodies. [import]uid: 49300 topic_id: 28216 reply_id: 114009[/import]

It should involve storyboard and where you place everything. I personally used director and don’t really know anything about storyboard. I will look into it later tonight when I get home if you aren’t able to figure it out, here is a helpful link that was talking about scene purging and removing stuff.

http://www.coronalabs.com/blog/2011/11/14/introducing-the-storyboard-api/

Check out Scene Purging and Removal, it talks about storyboard.purgeScene( sceneName ) and storyboard.removeScene( sceneName ). Maybe that’s what you are looking for. Let me know if you are able to figure it out or not. [import]uid: 77199 topic_id: 28216 reply_id: 114010[/import]

Found the problem!

[text]Important Restriction: Collision handling
Currently, the Box2D physics engine will reliably crash during a collision if Corona code attempts to modify objects still involved in the collision (since Box2D is still working out iterated mathematics on them).

The standard workaround is to “wait a bit”:

Do not modify / create / destroy physics objects during a collision, on penalty of crashing.
If you need to modify / create / destroy an object as a result of a collision, your collision handler should set a flag or add a time delay so the change can occur later, e.g. with timer.performWithDelay().[/text]

It works! [import]uid: 49300 topic_id: 28216 reply_id: 114014[/import]

Ah that makes sense. Seemed like an easy task wasn’t sure why it wasn’t working. Thanks for posting the reason and the solution, congrats on figuring it out as well. Best of luck [import]uid: 77199 topic_id: 28216 reply_id: 114015[/import]