diff --git a/include/Nazara/JoltPhysics3D/JoltCollider3D.hpp b/include/Nazara/JoltPhysics3D/JoltCollider3D.hpp index ed8fa0ba1..5fce14bb0 100644 --- a/include/Nazara/JoltPhysics3D/JoltCollider3D.hpp +++ b/include/Nazara/JoltPhysics3D/JoltCollider3D.hpp @@ -52,6 +52,7 @@ namespace Nz protected: template const T* GetShapeSettingsAs() const; + void ResetShapeSettings(); template void SetupShapeSettings(std::unique_ptr shapeSettings); private: @@ -80,7 +81,7 @@ namespace Nz struct ChildCollider; JoltCompoundCollider3D(std::vector childs); - ~JoltCompoundCollider3D() = default; + ~JoltCompoundCollider3D(); void BuildDebugMesh(std::vector& vertices, std::vector& indices, const Matrix4f& offsetMatrix) const override; @@ -118,7 +119,7 @@ namespace Nz inline JoltTranslatedRotatedCollider3D(std::shared_ptr collider, const Vector3f& translation); inline JoltTranslatedRotatedCollider3D(std::shared_ptr collider, const Quaternionf& rotation); JoltTranslatedRotatedCollider3D(std::shared_ptr collider, const Vector3f& translation, const Quaternionf& rotation); - ~JoltTranslatedRotatedCollider3D() = default; + ~JoltTranslatedRotatedCollider3D(); void BuildDebugMesh(std::vector& vertices, std::vector& indices, const Matrix4f& offsetMatrix) const override; diff --git a/include/Nazara/JoltPhysics3D/JoltCollider3D.inl b/include/Nazara/JoltPhysics3D/JoltCollider3D.inl index c4e202322..cb60a72d6 100644 --- a/include/Nazara/JoltPhysics3D/JoltCollider3D.inl +++ b/include/Nazara/JoltPhysics3D/JoltCollider3D.inl @@ -22,8 +22,9 @@ namespace Nz template void JoltCollider3D::SetupShapeSettings(std::unique_ptr shapeSettings) { - assert(!m_shapeSettings); shapeSettings->SetEmbedded(); // Call SetEmbedded on the template type to prevent compiler to resolve it outside of a file including Jolt + + assert(!m_shapeSettings); m_shapeSettings = std::move(shapeSettings); } diff --git a/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp b/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp index 7dd04ec78..eaf34a9df 100644 --- a/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp +++ b/src/Nazara/JoltPhysics3D/JoltCollider3D.cpp @@ -61,6 +61,11 @@ namespace Nz else return nullptr;// std::make_shared(); //< TODO } + + void JoltCollider3D::ResetShapeSettings() + { + m_shapeSettings.reset(); + } std::shared_ptr 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& vertices, std::vector& indices, const Matrix4f& offsetMatrix) const { for (const auto& child : m_childs) @@ -199,6 +210,12 @@ namespace Nz SetupShapeSettings(std::make_unique(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& vertices, std::vector& indices, const Matrix4f& offsetMatrix) const { const JPH::RotatedTranslatedShapeSettings* settings = GetShapeSettingsAs();