Does physics.stop() remove all bodies?

Hello everybody,

I am playing with the storyboard and physics API and experiencing arbitrary crashes (trial mode, on Windows). It looks like it is the physics API that is causing it, probably due to some faulty use of mine.

Each of my scenes does a physics.start() on scene create, and physics.stop() on scene exit.

I do NOT do any physics.removeBody

So, my question is, does physics.stop() also remove all bodies and frees the relevant memory? If not, shouldn’t there be a way to do so? like physics.removeAllBodies() method?

[import]uid: 145050 topic_id: 26793 reply_id: 326793[/import]

Hey Danny,

Yes, it removes bodies - run this sample and you’ll see the body disappear;
[lua]require ( “physics” )
physics.start()
physics.setGravity( 0, 7 )
physics.setDrawMode ( “hybrid” )

local myCircle = display.newCircle( 160, 240, 40 )
physics.addBody(myCircle)

local function stopTest()
physics.stop()
print “Stopped”
end
timer.performWithDelay(1000, stopTest, 1)

local function startTest()
physics.start()
print “Started”
end
timer.performWithDelay(2000, startTest, 1)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 26793 reply_id: 108808[/import]

Thanks Peach,

But actually there seems to be a problem. Not sure if it is a bug or a feature.

When there are only static bodies, the physics.stop() does NOT remove the bodies.

See a modified example. When both circles are static, bodies are not removed. When one is dynamic, it will remove bodies.

[lua]require ( “physics” )
physics.start()
physics.setGravity( 0, 7 )
physics.setDrawMode ( “hybrid” )

print “\n\n\n\n------”

local myCircle = display.newCircle( 100, 60, 40 )
physics.addBody(myCircle, “static”) – remove “static” and it works

local myStaticCircle = display.newCircle( 200, 60, 40 )
physics.addBody(myStaticCircle, “static”)

local function stopTest()
physics.stop()
print “Stopped”
end
timer.performWithDelay(1000, stopTest, 1)

local function startTest()
physics.start()
print “Started”
end
timer.performWithDelay(2000, startTest, 1)[/lua] [import]uid: 145050 topic_id: 26793 reply_id: 108812[/import]

Thank you for pointing that out - I’m actually unsure whether or not this is a bug or, as you said, a “feature”.

I’m going to get in touch with another member of the team and try to get an answer on this ASAP. [import]uid: 52491 topic_id: 26793 reply_id: 108820[/import]