Running local collision detection (Game Edition) produces unexpected crashes.

Hi there. I’m using game edition alpha and trying to remove ‘cities’ when they get hit with a bomb or a bullet. I’m trying to use table listeners to have the cities report when they are hit, and then remove themselves. It seems to work okay but after playing for half a minute or so, the simulation crashes with the following error:

Assertion failed: (0 \<= proxyId && proxyId \< m\_nodeCapacity), function GetFatAABB, file ../../external/Box2D\_v2.1.2/Box2D/Box2D/Collision/b2DynamicTree.h, line 141. /Applications/Corona Game Edition Alpha 1/Corona Terminal: line 9: 11564 Abort trap "$path/Corona Simulator.app/Contents/MacOS/Corona Simulator" $\* logout

Here’s the code I’m using -

local function onLocalCollision( self, event )  
 print("city one or two got hit")  
 self.parent:remove(self);  
 self.isBodyActive = false;  
 end  
  
city1.collision = onLocalCollision  
city1:addEventListener( "collision", city1 )  
  
city2.collision = onLocalCollision  
city2:addEventListener( "collision", city2 )  

Any advice is appreciated.

Nick [import]uid: 5232 topic_id: 1383 reply_id: 301383[/import]

Hi, Nick. There is a known bug with removing objects in Alpha 1, but this looks like a different bug, specifically involving remove(self) in a table listener.

The fix is probably the same for both, since it’s basically an object lifespan issue in the engine, but I’m logging this as a separate bug that includes your test case. Thanks! [import]uid: 3007 topic_id: 1383 reply_id: 3933[/import]

Hi Evan,

Thanks for your reply! I have two related questions - you may choose to answer any, all, or none of them!

  1. Is there a more appropriate (or currently working) way to remove these dynamically created display objects (and their attached physics bodies)?

  2. When can we expect Game Edition V2? :slight_smile:

Nick [import]uid: 5232 topic_id: 1383 reply_id: 3955[/import]

A bit more background:

* Your remove() line should be the way to do this, and currently it DOES do something, except that the C++ physics bodies are getting removed during the same “lazy” batch process that cleans up the C++ counterparts of Corona display objects. This currently takes 30 seconds or so, which is why it’s taking about that long for you to see the consequences (which are a crash and a message from the Box2D library, in this case).

* Obviously we want the physics to stay synchronized with the visible world, so this delay is wrong. But for other reasons, we’re experimenting with having more C++ objects get cleaned up more aggressively: there doesn’t seem to be a performance downside these days, and there’s definitely a memory-management upside. So this feature now ties into that.

* We are also planning to add a function to “un-physicalize” a display object without deleting it. What we really want there is “self.removeBody”, or similar. Like I said, that shouldn’t be necessary in this case (the line above should do it), but it would be helpful for some purposes where visible objects should move in and out of being physically simulated.

* In short, I don’t believe there is a current workaround. The crash might stop if you remove “self.isBodyActive = false”, but basically removal isn’t properly implemented in the current Alpha.

This removal problem still exists in Alpha 2 (released Monday for the Casual Connect and Stanford demos), but is now at top priority for fixing, since it’s kind of a major showstopper in cases like this!
[import]uid: 3007 topic_id: 1383 reply_id: 4094[/import]

hi,

i don’t know if this is relevant, but with the work i’ve done with Box2D in Flash you shouldn’t remove bodies from the physics world immediately. You need to set a flag for each body to destroy and then remove that list of bodies outside of the physics step.

does this need doing at the Corona SDK level, rather than by us developers?

j [import]uid: 6645 topic_id: 1383 reply_id: 4121[/import]

@j - Good question (I’ve used Flash Box2D also), but Corona takes care of all that for you.

In versions beyond alpha 2, you can do object:removeSelf() whevever you like, and Corona will automatically wait until the end of the physics step to remove the Box2D object. This will even work during the “postSolve” collision phase, if you want to destroy objects after testing collision forces – it should be totally bulletproof. This is a case where there’s basically one right way to do things, so we should just handle it in the background.

Again, this is simply broken in alphas 1 and 2 – it’s not you, it’s us! :slight_smile: [import]uid: 3007 topic_id: 1383 reply_id: 4129[/import]

Is there a fix yet for this issue yet? I’m having the same problem. Yes seems to be because of self.isBodyActive = false [import]uid: 13826 topic_id: 1383 reply_id: 19882[/import]

phew…I was starting to think there was something really wrong with my code. The constant crashing I was facing was because of the self.isBodyActive = false I had placed in my collision event listener.

I guess a workaround would consist of checking if something like self.isHit is false when the collision event occurs and setting it to true if its not. [import]uid: 30491 topic_id: 1383 reply_id: 21479[/import]