Physics2D/PhysWorld2D: Fix SetMass calls during callbacks

This commit is contained in:
Jérôme Leclercq
2017-03-07 09:36:29 +01:00
parent ede6dd90b8
commit 78d6a69bcb
3 changed files with 73 additions and 6 deletions

View File

@@ -249,15 +249,18 @@ namespace Nz
cpBodySetMoment(m_handle, m_geom->ComputeInertialMatrix(m_mass));
}
else
cpBodySetType(m_handle, CP_BODY_TYPE_STATIC);
m_world->RegisterPostStep(this, [this]() { cpBodySetType(m_handle, CP_BODY_TYPE_STATIC); } );
}
else if (mass > 0.f)
{
if (cpBodyGetType(m_handle) == CP_BODY_TYPE_STATIC)
{
cpBodySetType(m_handle, CP_BODY_TYPE_DYNAMIC);
cpBodySetMass(m_handle, mass);
cpBodySetMoment(m_handle, m_geom->ComputeInertialMatrix(m_mass));
m_world->RegisterPostStep(this, [this, mass]()
{
cpBodySetType(m_handle, CP_BODY_TYPE_DYNAMIC);
cpBodySetMass(m_handle, mass);
cpBodySetMoment(m_handle, m_geom->ComputeInertialMatrix(m_mass));
});
}
}