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 Did you ever find a workaround for this? [import]uid: 7177 topic_id: 1637 reply_id: 5055[/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]
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]
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.
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]
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]