Physics3D: Ensure RigidBody are destroyed on world destruction
This commit is contained in:
@@ -418,6 +418,17 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
void RigidBody3D::Destroy()
|
||||
{
|
||||
if (m_body)
|
||||
{
|
||||
NewtonDestroyBody(m_body);
|
||||
m_body = nullptr;
|
||||
}
|
||||
|
||||
m_geom.reset();
|
||||
}
|
||||
|
||||
void RigidBody3D::UpdateBody(const Matrix4f& transformMatrix)
|
||||
{
|
||||
NewtonBodySetMatrix(m_body, &transformMatrix.m11);
|
||||
|
||||
@@ -8,13 +8,19 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Physics3DSystem::Physics3DSystem(entt::registry& registry)
|
||||
Physics3DSystem::Physics3DSystem(entt::registry& registry) :
|
||||
m_registry(registry)
|
||||
{
|
||||
m_constructConnection = registry.on_construct<RigidBody3DComponent>().connect<OnConstruct>();
|
||||
}
|
||||
|
||||
Physics3DSystem::~Physics3DSystem()
|
||||
{
|
||||
// Ensure every NewtonBody is destroyed before world is
|
||||
auto rigidBodyView = m_registry.view<RigidBody3DComponent>();
|
||||
for (auto [entity, rigidBodyComponent] : rigidBodyView.each())
|
||||
rigidBodyComponent.Destroy();
|
||||
|
||||
m_constructConnection.release();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user