Removing Physics Objects bug?

I’m having trouble removing physics objects. I made a post about it in this thread:

http://developer.anscamobile.com/forum/2011/01/27/insights-needed-non-trivial-physics-object-removal-more-one-source

And still haven’t got it working perfectly.

I’m removing physics objects on collisions to the ground, which works perfectly, but I also have a timer and when it reaches zero I want to remove any object that hasn’t hit the ground yet.

I’m checking whether the object exists with object ~= nil then object:removeSelf(), but I still get the trying to removeSelf() a nil value error from time to time. Always randomly though, so it’s really hard to debug.

I also print the object before removing it. These are table values so I get a location. However when I get a error the print will say nil. But Corona removes it anyway and I get an error. Even though I have an “if” that should prevent this.

As of now I’m pausing the physics world and then removing the display objects. When it fails, on the device, the display objects remain frozen on screen, but the app continues to work. However I’m supposed to have X number of objects on screen and I will have X + the ones that got frozen next time I start the level (which is not acceptable). On the simulator it crashes and will log out.

I really don’t know what else to do to fix this. I’ve tried pretty much everything I can think of, any help would be appreciated. [import]uid: 10835 topic_id: 5991 reply_id: 305991[/import]

Have you tried checking to see if removeSelf exists?
like:
[lua]if object and object.removeSelf then object:removeSelf() end[/lua]

-Angelo [import]uid: 12822 topic_id: 5991 reply_id: 20942[/import]

I was using if object ~= nil also and was getting quirky results, especially in the daily builds coming out. I like your method better. Thanks. [import]uid: 6084 topic_id: 5991 reply_id: 23032[/import]