JoltPhysics3D: Fix crash when freeing compoites colliders

This commit is contained in:
SirLynix
2023-03-25 14:19:05 +01:00
committed by Jérôme Leclercq
parent b3595178a1
commit 2b0239b8f0
3 changed files with 22 additions and 3 deletions

View File

@@ -61,6 +61,11 @@ namespace Nz
else
return nullptr;// std::make_shared<NullCollider3D>(); //< TODO
}
void JoltCollider3D::ResetShapeSettings()
{
m_shapeSettings.reset();
}
std::shared_ptr<JoltCollider3D> JoltCollider3D::CreateGeomFromPrimitive(const Primitive& primitive)
{
@@ -156,6 +161,12 @@ namespace Nz
SetupShapeSettings(std::move(shapeSettings));
}
JoltCompoundCollider3D::~JoltCompoundCollider3D()
{
// We have to destroy shape settings first as it carries references on the inner colliders
ResetShapeSettings();
}
void JoltCompoundCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
{
for (const auto& child : m_childs)
@@ -199,6 +210,12 @@ namespace Nz
SetupShapeSettings(std::make_unique<JPH::RotatedTranslatedShapeSettings>(ToJolt(translation), ToJolt(rotation), m_collider->GetShapeSettings()));
}
JoltTranslatedRotatedCollider3D::~JoltTranslatedRotatedCollider3D()
{
// We have to destroy shape settings first as it carries references on the inner collider
ResetShapeSettings();
}
void JoltTranslatedRotatedCollider3D::BuildDebugMesh(std::vector<Vector3f>& vertices, std::vector<UInt16>& indices, const Matrix4f& offsetMatrix) const
{
const JPH::RotatedTranslatedShapeSettings* settings = GetShapeSettingsAs<JPH::RotatedTranslatedShapeSettings>();