Random crashes after I started using physics.

Hi,
I made a nice set of menus and everything worked fine until I created one extra screen and started using physics.
After going to this screen my app starts to crash in random places. Sometimes when I go back to the other menus, sometimes the rope gets cut half way, sometimes it even works for five minutes or so, but never longer. It's really frustrating because I can't debug it at all - the whole SDK just crashes leaving me clueless.
Btw, it crashes on my mac too, and on my iPhone 3G.
I wanted to buy the full version but I don't see the point. I get a crash every minute!

Please help me!

Am I doing something wrong? Random crashes make me think it's not really mu fault.
Here's the code for the guilty screen where I have my rope:

local screenW = display.contentWidth; screenH = display.contentHeight

function New()

local levelObjects = display.newGroup()
local ground = display.newImage("res/ground.png")
local ground2 = display.newImage("res/ground.png")
local joints = {}
local pieces = {}
local bodies = {}
local function createRope(length,startx,starty)
local prevPiece
local rope = display.newGroup()
for i=1,length do
if (i == length) then
pieces[i] = display.newImage("res/in-game/rope_end.png")
pieces[i].y = starty + (i-1)*14+6; pieces[i].x = startx + screenW / 2
else
pieces[i] = display.newImage("res/in-game/rope_piece.png")
pieces[i].y = starty + (i-1)*14; pieces[i].x = startx + screenW / 2
end
rope:insert(pieces[i], false)

bodies[i] = physics.addBody( pieces[i], { density=2, friction=0.5, bounce=0 } )
if (i > 1) then prevPiece = pieces[i-1]
else prevPiece = ground end
joints[i] = physics.newJoint( "pivot", prevPiece, pieces[i], startx + screenW / 2, starty + (i-1)*14 )
joints[i].isLimitEnabled = true
joints[i]:setRotationLimits( -3, 3 )
end
levelObjects:insert(rope, true)

pieces[20]:applyForce( math.random(-250,300), 0, pieces[20].x, pieces[20].y )
return rope
end

-- physics.setDrawMode( "hybrid" )

levelObjects:insert(ground, true)
levelObjects:insert(ground2, true)

ground.y=0; ground2.y = 460; ground2.x = 160; ground.x = 160
physics.addBody( ground, "static", { friction=0.5} )
physics.addBody( ground2, "static", { friction=10} )
ground2.rotation = math.random(-30,30)

createRope(20,0,30)

return levelObjects
end

Regards
M

I'm assuming you are calling physics.start() at some point, which isn't in your code sample. This can crash the simulator (creating bodies w/o first starting the simulation). It's not clear to me looking at your code why it's crashing, but the physics engine can be intolerant of "bad" values--for example, the sim will crash if you try to create a new joint from a non-physics body, or if you pass invalid shape coordinates when creating a new body. The fact that it's random makes it harder to troubleshoot.

I would recommend using the command line debugger to set a break point or two in that code, and step through it. See if you can better isolate where/when the crash is occurring.

Tim

Hi Tim,
Thanks a bunch for your help.
I've done some debugging and it's the physics.stop() that's crashing my app randomly. I just call it every time I leave this screen and then I restart the physics when coming back.
Usually after 2-3 times it hangs up. Sometimes it takes 10 times though :).
When I remove the physics.stop() then everything works like a charm. Adding it back makes the random crashes appear again.
Is there any workaround for this issue? Is it just a bug in the SDK?
I suppose it may be related to the thing discussed here:
http://developer.anscamobile.com/forum/2010/11/25/removing-physics-bodies#comment-12303

What to do? Please help.
Regards
m

I would like to know a work around, too. I have the same exact symptoms; hard simulator AND device crashes with "bus error" when stopping and restarting physics using physics.stop(), anytime between 2 and 20 times after calling it repeatedly (as when I tear down and build up a new level during a multi-level play session).

I need some kind of work around since if I don't call physics.stop() I get residual physical effects from the old level even though I'm not reusing any objects from that level. Physics.stop() works great at resetting the physics engine, except for the intermittent crash which renders the game unshippable.

I also have been having REALLY strange crash issues, i dont know if its related to your guys's issues, but for me, the simulator crashes anytime i reload a Scene or also just Relaunching the simulator. And so i start commenting out sections of code that i think might be a problem, and after do so much, it finally starts not crashing, then i uncomment all the code, so its back to its original state, and now everything works fine.... i have seen this in the past and mentioned it to carlos but no one has looked into it. so strange, its for sure a simulator problem, it comes and goes for me

Alright Guys, ive done more testing with my project, and when i comment out my Physics.stop() my random crashing disappears, this really seems to be the culprit, i have had this problem forever, im glad its finally getting pin pointed. Also, i dont know if this crash occurs for you guys, but when i open my project, and choose relaunch twice in a row without interacting with my game, the simulator crashes. Just tested it on a sample code project as well and it crashed when relaunched twice. Anyways thats my news, i hope Ansca can start working on this, its wasted soo much of my time looking for my own coding errors.

I have same problem as rxmarccall... Without using physics.stop() my app runs good without crashing...

Here is error what I'm getting :

1
2
3
4
/Applications/CoronaSDK/Corona Terminal: line 9:   691 Bus error               "$path/Corona Simulator.app/Contents/MacOS/Corona Simulator" $*
logout
 
[Process completed]

Ansca, please take a look at this, this is something serious. This is a show stopping bug in my opinion, I soon want to release my game and rather would not have it crashing because of this.

I entered a bug for this in the bug base. I hope Ansca takes a crack at it since it seems to be biting a lot of people.

The workaround that ended up working for me is to just make absolutely sure you remove/delete ALL physics bodies before calling physics.stop(). Create a physics world cleanup function that iterates through the physics child objects and deletes them all before calling physics.stop(). Then you are free to build a new physics world and fire it up with physics.start() without a crash.

views:2139 update:2011/10/10 9:00:20
corona forums © 2003-2011