error in the console log. But, nothing on the simulator when calling physics.stop() during a collision.

Hi, Corona Community.

I get an error when I call physics.stop() during a collision. Just like this : 

local function onCollision(e) if e.phase == "began" then if e.target.type == "ok" then Runtime:removeEventListener("enterFrame", e.target) display.remove( e.target ) points = points+1 if points == Amount then physics.stop() print("U WIN") removeAll = function(group) if group.enterFrame then Runtime:removeEventListener("enterFrame", group); end if group.touch then group:removeEventListener("touch", group); Runtime:removeEventListener("touch", group); end for i = group.numChildren, 1, -1 do if group[i].numChildren then removeAll(group[i]); else if group[i].enterFrame then Runtime:removeEventListener("enterFrame", group[i]); end if group[i].touch then group[i]:removeEventListener("touch", group[i]); Runtime:removeEventListener("touch", group[i]); end end end end removeAll(group); end

the error as in the terminal :

ERROR: 72.lua:107: physics.stop() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event

Is this going to affect the game when it’s built to a device? everything is fine on the simulator. 

what does “physics.stop() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event” mean?

Are you saying that, even though you receive that error, the physics.stop() call is being demonstrated? You might want to go over the Gotchas section of the physics.stop() API.

Hi, Alex.

Yes. Even though I get the error, everything is working as it should be. I’m just afraid that the game won’t function appropriately.

I took a look at what mentioned. Does that mean everything is fine since it says : your collision handler may set a flag or include a time delay via timer.performWithDelay() so that the action can occur in the next application cycle or later.

up

Hi @hammod-930,

Take a look at this guide, a little ways down, for the yellow box that indicates which APIs you should not call during a collision frame:

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html#collision-filtering

“physics.stop()” is one of those, so yes, I highly recommend that you wait one cycle (via timer or otherwise) which delays that call being made during the collision. If you don’t, you definitely risk the game crashing.

Best regards,

Brent

Hi @Brent Sorrentino

Thank you. setting a timer like this showed no errors:

timer.performWithDelay( 1, function() physics.stop() print( "physics stopped" ) end , 1)

thanks :slight_smile:

Are you saying that, even though you receive that error, the physics.stop() call is being demonstrated? You might want to go over the Gotchas section of the physics.stop() API.

Hi, Alex.

Yes. Even though I get the error, everything is working as it should be. I’m just afraid that the game won’t function appropriately.

I took a look at what mentioned. Does that mean everything is fine since it says : your collision handler may set a flag or include a time delay via timer.performWithDelay() so that the action can occur in the next application cycle or later.

up

Hi @hammod-930,

Take a look at this guide, a little ways down, for the yellow box that indicates which APIs you should not call during a collision frame:

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html#collision-filtering

“physics.stop()” is one of those, so yes, I highly recommend that you wait one cycle (via timer or otherwise) which delays that call being made during the collision. If you don’t, you definitely risk the game crashing.

Best regards,

Brent

Hi @Brent Sorrentino

Thank you. setting a timer like this showed no errors:

timer.performWithDelay( 1, function() physics.stop() print( "physics stopped" ) end , 1)

thanks :slight_smile: