Cant add a physics body

I am very familiar with all of the physics and the commands in Corona, and I have regular success with most physics objects, but Im experiencing a problem that seems out of the ordinary.

I have an object that falls, hits a sensor, the sensors triggers a function which I called step9(). Here is the function

1
2
3
4
5
6
function step9()
        TestBox = display.newRect (15, 15, 64, 60)
        print("Line 1")
        physics.addBody ( TestBox, "static", { isSensor = false} )
        print("Line 2")
end

Had the exact same problem one day and now I'm beating my head on the desk trying to remember what it was...I'll look through my comments to see if I can find it...

I forgot to mention that it only happens when I do anything through the sensor. If I call the function before the sensor is passed, step9 works. Its almost as if the sensor cripples it somehow, even though all it has is to call step9

couldn't find anything concrete. I know I have had ups and downs with the isSensor property.

It seems like you may be attempting to alter the physics environment while an event is still taking place. The call to this function, is it within a timer.performWithDelay() ?

ie>
-Physics Event Listener-
timer.performWithDelay(30, step9)

TheRealTonyK is correct. You cannot add another body while a physics event is taking place. You need to do so with a slight delay.

ie

1
2
--When step9 should be called
timer.performWithDelay(1, step9)

Ahhhh there we go, that solved it. Ill have to keep this in mind down the road. Thanks a lot guys!

views:1349 update:2011/10/4 17:12:07
corona forums © 2003-2011