Physics2D/RigidBody2D: Fix SetMass occasionnal crash
This commit is contained in:
parent
78d6a69bcb
commit
43f8f21df6
|
|
@ -245,23 +245,26 @@ namespace Nz
|
||||||
{
|
{
|
||||||
if (mass > 0.f)
|
if (mass > 0.f)
|
||||||
{
|
{
|
||||||
cpBodySetMass(m_handle, mass);
|
m_world->RegisterPostStep(this, [this, mass]()
|
||||||
cpBodySetMoment(m_handle, m_geom->ComputeInertialMatrix(m_mass));
|
{
|
||||||
|
cpBodySetMass(m_handle, mass);
|
||||||
|
cpBodySetMoment(m_handle, m_geom->ComputeInertialMatrix(m_mass));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_world->RegisterPostStep(this, [this]() { cpBodySetType(m_handle, CP_BODY_TYPE_STATIC); } );
|
m_world->RegisterPostStep(this, [this]() { cpBodySetType(m_handle, CP_BODY_TYPE_STATIC); } );
|
||||||
}
|
}
|
||||||
else if (mass > 0.f)
|
else if (mass > 0.f)
|
||||||
{
|
{
|
||||||
if (cpBodyGetType(m_handle) == CP_BODY_TYPE_STATIC)
|
m_world->RegisterPostStep(this, [this, mass]()
|
||||||
{
|
{
|
||||||
m_world->RegisterPostStep(this, [this, mass]()
|
if (cpBodyGetType(m_handle) == CP_BODY_TYPE_STATIC)
|
||||||
{
|
{
|
||||||
cpBodySetType(m_handle, CP_BODY_TYPE_DYNAMIC);
|
cpBodySetType(m_handle, CP_BODY_TYPE_DYNAMIC);
|
||||||
cpBodySetMass(m_handle, mass);
|
cpBodySetMass(m_handle, mass);
|
||||||
cpBodySetMoment(m_handle, m_geom->ComputeInertialMatrix(m_mass));
|
cpBodySetMoment(m_handle, m_geom->ComputeInertialMatrix(m_mass));
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
m_mass = mass;
|
m_mass = mass;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue