Physics crash

A function that creates an explosion:

local Explosion = function( x, y, size ) local explosion = sprite.newSprite( fxExplosionSpriteSet ) explosion.x = x explosion.y = y explosion.explosion = true if size then explosion:scale( size, size ) else explosion:scale( 1.5, 1.5 ) end explosion:prepare( "fx\_explosion" ) explosion:play() explosion:addEventListener( "sprite", KillSprite ) --physics.addBody( explosion, "dynamic", { isSensor = true, density = 5.0, friction = 0.5, bounce = 0.3 } ) end

Occasionally there are items on the screen and if the player taps on one it is handled as follows:

if item.itemType == ITEM\_HEALTH then SetHealth( health + 10 ) elseif item.itemType == ITEM\_ENERGY\_X2 then elseif item.itemType == ITEM\_ExP\_X2 then elseif item.itemType == ITEM\_BOMB then Explosion( item.x, item.y, 3 ) end

The bomb item leaves an explosion that kills any enemy it touches while it exists. I was trying to add a physics body to the explosion to detect collision events but when I do I get the following crash:

Assertion failed: (IsLocked() == false), function CreateBody, file /Users/ansca/.hudson/jobs/Pong-DMG/workspace/platform/mac/…/…/external/Box2D_v2.1.2/Box2D/Box2D/Dynamics/b2World.cpp, line 84.
/Applications/Corona Game Edition Alpha 2/Corona Terminal: line 9: 43606 Abort trap “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
logout
[import]uid: 6259 topic_id: 1637 reply_id: 301637[/import]

I just started getting the same crash. And i see no know has responded :frowning: Did you ever find a workaround for this? [import]uid: 7177 topic_id: 1637 reply_id: 5055[/import]

Probably an obvious one, but it caught me out: have you firstly called physics.start() ? [import]uid: 3953 topic_id: 1637 reply_id: 5058[/import]

The Ansca guys are looking into it. I narrowed it down to the removeSelf() call on these physics objects before I sent it to them. Will have to wait and see what they find out. [import]uid: 6259 topic_id: 1637 reply_id: 5059[/import]

I had it too - turns out for me it was the physics.start() - thx MarkHenryC [import]uid: 9175 topic_id: 1637 reply_id: 6318[/import]

@NeoBlargg,

Have you figured this out or heard back from Ansca? I am having the same problem… [import]uid: 8194 topic_id: 1637 reply_id: 6661[/import]

@dknell,

My Corona project has been on hold for the past while, but from what I can remember the crash involved adding/removing physics bodies, usually from event handlers. ie. not the main thread.

I would try commenting out any code that adds or removes physics bodies. Stepping through in the debugger won’t work because the actual adding/removal does not occur in the same frame. I’ll post here when I figure it out or let me know if you do. [import]uid: 6259 topic_id: 1637 reply_id: 6681[/import]

Rising this topic from the grave.

I started having this problem as well, but no matter how I try to isolate it, I always get the crash.

The first objects I create on my scene - and even by another function that’s constantly creating them - work fine.

On this particular creation, that happens after a physics collision, the simulator crashes. I tried removing properties, changing coordinates, using the same values as the other objects… But none of this worked out.

HELP! :stuck_out_tongue: [import]uid: 11130 topic_id: 1637 reply_id: 11966[/import]

Just started getting this error.

Assertion failed: (m_world->IsLocked() == false), function SetTransform, file /Users/ansca/.hudson/jobs/Main-DMG/workspace/platform/mac/…/…/external/Box2D_v2.1.2/Box2D/Box2D/Dynamics/b2Body.cpp, line 395.
/Applications/Corona.243/Corona Terminal: line 9: 14560 Abort trap “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
logout

My guess is it might have something to do with this:
http://www.box2d.org/forum/viewtopic.php?f=19&t=6063 [import]uid: 11024 topic_id: 1637 reply_id: 15312[/import]

finnk wins the prize :smiley:

I found that I got this crash when adding a physics body in the same timestep as destroying one.
Solution :

Wrap the code that creates the body in the following code

[lua]timer.performWithDelay(1,function()
…code…
…goes…
…here…
end,1)[/lua]
and it now works sweet! [import]uid: 34945 topic_id: 1637 reply_id: 45586[/import]

Thanks innominata. The timer trick works great!

The timer workaround worked like a charm for me. I had figured out that the my crashing issue was related to the addition of the physics body, however I did not think of delaying a bit so that it gets delayed to the next “tick” . Hope the Ansca guys figure this out soon. In the meantime, your work around is the way to go for me. [import]uid: 52675 topic_id: 1637 reply_id: 47076[/import]

You’re welcome :slight_smile: [import]uid: 34945 topic_id: 1637 reply_id: 47083[/import]