Hello,
I just pulled my hair out over this problem and was hoping to save other AS3 developers' hair. Sorry if this solution is a duplicate.
I'm using the AS3 port of Box2D. If DestroyBody is not working and you're using userData, try setting the userData to null just before calling DestroyBody:
Before "o.m_userData = null" was added, the shape was still available for contact filtering.
If you're not using userData and DestroyBody is not working, it's time for a "reference audit".
-Mike
I just pulled my hair out over this problem and was hoping to save other AS3 developers' hair. Sorry if this solution is a duplicate.
I'm using the AS3 port of Box2D. If DestroyBody is not working and you're using userData, try setting the userData to null just before calling DestroyBody:
Code:
...
var o = this.getBodyFromUserData(mc);
if(null != o)
{
o.m_userData = null;
this.world.DestroyBody(o);
}
...
public function getBodyFromUserData(mc:MovieClip):b2Body
{
for (var b:b2Body = this.m_world.GetBodyList(); b; b = b.GetNext())
{
if(b.m_userData == mc)
{
return b;
}
}
return null;
}
var o = this.getBodyFromUserData(mc);
if(null != o)
{
o.m_userData = null;
this.world.DestroyBody(o);
}
...
public function getBodyFromUserData(mc:MovieClip):b2Body
{
for (var b:b2Body = this.m_world.GetBodyList(); b; b = b.GetNext())
{
if(b.m_userData == mc)
{
return b;
}
}
return null;
}
Before "o.m_userData = null" was added, the shape was still available for contact filtering.
If you're not using userData and DestroyBody is not working, it's time for a "reference audit".
-Mike