The infamous physics crash - cannot resolve

Hi guys

I’ve had this problem for the past few days now and can’t seem to figure it out.

Basically I have a player which is kinematic and then turns dynamic. The player is able to collect items, which are kinematic. Here’s where the fun starts.

On collision I get random errors. Sometimes it seems to be working, but then all of a sudden, error!

These are just some of the errors I get (not at once):
/Applications/CoronaSDK/Corona Terminal: line 9: 2507 Bus error “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
logout

[Process completed]

/Applications/CoronaSDK/Corona Terminal: line 9: 2536 Bus error “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
logout

[Process completed]

/Applications/CoronaSDK/Corona Terminal: line 9: 2579 Bus error “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
logout

[Process completed]
I have also tried “delaying” the collision as recommended but even that doesn’t work.

Sometimes the collision is fired more than once for some bizarre reason but I don’t know if that’s relevant or not.
Please could someone take a look at this as I do not have much hair left anymore due to me pulling it out :stuck_out_tongue: [import]uid: 40538 topic_id: 13959 reply_id: 313959[/import]

remove the event listener on the items on collision, then put the other code executed on delay on a timer. You can’t really modify physics objects on collision, as the physics engine is still using them. Post some code up. [import]uid: 68741 topic_id: 13959 reply_id: 51368[/import]

I cannot remove the event listeners as I will be reusing the item again.

The collision delay seems to have worked for everyone but me for some reason.
The code I have can be found here:

http://developer.anscamobile.com/forum/2011/08/13/issensor-causing-multiple-collisions
That is the majority of the code involved. [import]uid: 40538 topic_id: 13959 reply_id: 51377[/import]

Hi w.baig84.

Just curious as to why your structuring your code like that. With the code below you can use one collision function to check against any colliding objects. Also I implemented a simpler way to create a new coin on collision.

This is how I would recommend doing it (let me know if it works!) :
(Based on the code you linked to )

local player = display.newImageRect(img1, playerW, playerH)  
player:setReferencePoint(display.CenterReferencePoint)  
physics.addBody( player, physicsData:get(physInfo) )  
player.bodyType = "kinematic"  
player.isFixedRotation = true  
player.xScale = playerScale  
player.yScale = playerScale  
player.x = 50  
player.y = \_H / 2  
player.name = "player"  
   
   
local coin1 ={}  
local coins1  
  
coins1 = {2,2.25,2.5,2.75,3}  
local rand3 = math.random (2, #coins1 )  
local coin1 = movieclip.newAnim{ "images/coins/coin1@2x.png",  
 "images/coins/coin2@2x.png",  
 "images/coins/coin3@2x.png",  
 "images/coins/coin4@2x.png",  
 "images/coins/coin5@2x.png",  
 "images/coins/coin6@2x.png",  
 "images/coins/coin7@2x.png",  
 "images/coins/coin8@2x.png",  
 "images/coins/coin9@2x.png",  
 "images/coins/coin8@2x.png",  
 "images/coins/coin7@2x.png",  
 "images/coins/coin6@2x.png",  
 "images/coins/coin5@2x.png",  
 "images/coins/coin4@2x.png",  
 "images/coins/coin3@2x.png",  
 "images/coins/coin2@2x.png",  
 "images/coins/coin1@2x.png",  
   
 }  
coin1.xScale = 0.5  
coin1.yScale = 0.5  
coin1:play()  
coin1:setReferencePoint(display.CenterReferencePoint)  
  
localGroup:insert(coin1)  
physics.addBody( coin1,"kinematic", {isSensor = true, radius = 13})  
coin1.name = "coin 1"  
coin1.x = \_W \* 2 + \_W/2  
coin1.y = \_H / rand3  
   
   
local coin2 ={}  
local coins2  
coins2 = {2,2.25,2.5,2.75,3}  
local rand4 = math.random (2, #coins2 )  
local coin2 = movieclip.newAnim{ "images/coins/coin1@2x.png",  
 "images/coins/coin2@2x.png",  
 "images/coins/coin3@2x.png",  
 "images/coins/coin4@2x.png",  
 "images/coins/coin5@2x.png",  
 "images/coins/coin6@2x.png",  
 "images/coins/coin7@2x.png",  
 "images/coins/coin8@2x.png",  
 "images/coins/coin9@2x.png",  
 "images/coins/coin8@2x.png",  
 "images/coins/coin7@2x.png",  
 "images/coins/coin6@2x.png",  
 "images/coins/coin5@2x.png",  
 "images/coins/coin4@2x.png",  
 "images/coins/coin3@2x.png",  
 "images/coins/coin2@2x.png",  
 "images/coins/coin1@2x.png",  
   
 }  
coin2.xScale = 0.5  
coin2.yScale = 0.5  
coin2:play()  
coin2:setReferencePoint(display.CenterReferencePoint)  
localGroup:insert(coin2)  
 physics.addBody( coin2,"kinematic", {isSensor = true, radius = 13})  
 coin2.name = "coin 2"  
 coin2.x = \_W \* 3 + \_W/2  
 coin2.y = \_H / rand4  
   
   
   
local function createCoin(x, y)  
 local coinAnim = movieclip.newAnim{ "images/coins/coin1@2x.png",  
 "images/coins/coin2@2x.png",  
 "images/coins/coin3@2x.png",  
 "images/coins/coin4@2x.png",  
 "images/coins/coin5@2x.png",  
 "images/coins/coin6@2x.png",  
 "images/coins/coin7@2x.png",  
 "images/coins/coin8@2x.png",  
 "images/coins/coin9@2x.png",  
 "images/coins/coin8@2x.png",  
 "images/coins/coin7@2x.png",  
 "images/coins/coin6@2x.png",  
 "images/coins/coin5@2x.png",  
 "images/coins/coin4@2x.png",  
 "images/coins/coin3@2x.png",  
 "images/coins/coin2@2x.png",  
 "images/coins/coin1@2x.png",  
   
 }  
  
 coinAnim.x = x  
 coinAnim.y = y  
 coinAnim.xScale = 0.5  
 coinAnim.yScale = 0.5  
 coinAnim:play()  
 coinAnim:setReferencePoint(display.CenterReferencePoint)  
 localGroup:insert(coinAnim)  
  
 return coinAnim  
  
end  
   
   
local function onLocalCollision( event )  
 local obj1 = event.obj1  
 local obj2 = event.obj2  
  
 if ( event.phase == "began") then  
 if (obj1.name == "player" and obj2.name == "coin 1" or obj1.name == "player" and obj2.name == "coin 2" then  
 myCoinsNew = myCoinsNew + myCoinsVar  
 coinsText.text = "x "..myCoinsNew  
  
 --Create a coin   
 local coinAnim = createCoin(obj2.x, obj2.y)  
  
 obj2.isBodyActive = false  
 obj2.isVisible = false  
  
 trans1 = transition.to( coinAnim, { time=1500, x=480, y=75, alpha = 0})  
 end  
 end  
 return true  
end  
   
  
Runtime:addEventListener("collision", onLocalCollision)  
  

PS : Sorry about the formatting, the original linked code was very unformatted (in a readable sense :slight_smile: ) [import]uid: 84637 topic_id: 13959 reply_id: 51428[/import]

Hi Danny,

Sorry about the formatting - I was just plucking bits out which I though might be relevant from 2 or 3 modules, and so didn’t have time to format it properly.

Glad it was still readable though and I will be doing a clean up if I can get this sorted :slight_smile:

I’ll definately try it!
In the meantime, is there any chance you can confirm the following.

If an object is set to be a sensor - if it collides with another physical object, is the collision meant to keep firing until the other object fully passes through it?
Thanks [import]uid: 40538 topic_id: 13959 reply_id: 51434[/import]

@Danny

I did have to change the local obj1 & local obj2 to equal event.object1 & event.object2, and it was all going fine until the dreaded crash again!!
/Applications/CoronaSDK/Corona Terminal: line 9: 2943 Bus error “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*
logout

[Process completed]

I am now officially bald :slight_smile: [import]uid: 40538 topic_id: 13959 reply_id: 51438[/import]

Whoops, sorry about that. It should have been event.object1 etc.

Fancy zipping up a test version of your code complete with any assets it needs to run and emailing them to danny@anscamobile.com ?

Something is up, i’m sure I can come up with a solution for you however, if you send me a example to work of that exhibits the crashing.

Thanks [import]uid: 84637 topic_id: 13959 reply_id: 51527[/import]

It turns out that it could be the fact that my dynamic object is a complex shape, as it works flawlessly if the objects physical shape is simple rectangle.

Even the isSensor property works perfectly… [import]uid: 40538 topic_id: 13959 reply_id: 51565[/import]

Does your dynamic object have more than 8 points? Is it made up in a clockwise manor ?

If not there is your answer i guess :slight_smile: [import]uid: 84637 topic_id: 13959 reply_id: 51572[/import]

I’ve been reducing the points since my last post - think it may be that :frowning:

It’s just a shame though that it’s not as straightforward as I would have liked. [import]uid: 40538 topic_id: 13959 reply_id: 51575[/import]

I don’t know how you are calculating your points, but I use Physics Shape Panel for Adobe Fireworks (for convenience) and if i am ever in a situation where a body needs more than 8 points i just add multiple bodies to the same object to make a more complicated shape.

Maybe try that :slight_smile: [import]uid: 84637 topic_id: 13959 reply_id: 51576[/import]

In that case, it is multiple bodied elements which are causing the problem.

I’m using Physics Editor and it seems like the collision is firing depending on how many parts of the other body it comes in contact with.
It doesn’t help that my multiple bodied player can be hit from all sides.
Any chance of a work around for this? [import]uid: 40538 topic_id: 13959 reply_id: 51579[/import]