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

[lua]function step9()
TestBox = display.newRect (15, 15, 64, 60)
print(“Line 1”)
physics.addBody ( TestBox, “static”, { isSensor = false} )
print(“Line 2”)
end[/lua]

It creates a white 64x60 box in the top left 15x15 away, in the right place where it should be, but I cant add any physics to it. The console prints Line 1, but never gets to Line 2. At first I thought I must just be missing something like a misspelled word, but unless I’ve entirely lost my marbles, I dont think I am. Changing the parameters does nothing.

There are other physics objects in the scene which are still capable of moving and doing things, but this is puzzling me even though it seems like it should be obvious. [import]uid: 67886 topic_id: 14506 reply_id: 314506[/import]

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…

[import]uid: 21331 topic_id: 14506 reply_id: 53658[/import]

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 [import]uid: 67886 topic_id: 14506 reply_id: 53676[/import]

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) [import]uid: 21331 topic_id: 14506 reply_id: 53731[/import]

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

--When step9 should be called timer.performWithDelay(1, step9) [import]uid: 84637 topic_id: 14506 reply_id: 53732[/import]

Ahhhh there we go, that solved it. Ill have to keep this in mind down the road. Thanks a lot guys! [import]uid: 67886 topic_id: 14506 reply_id: 53798[/import]