diff --git a/modules/jolt_physics/jolt_physics_server_3d.cpp b/modules/jolt_physics/jolt_physics_server_3d.cpp index cfb1f3b641..b2a39613ac 100644 --- a/modules/jolt_physics/jolt_physics_server_3d.cpp +++ b/modules/jolt_physics/jolt_physics_server_3d.cpp @@ -52,6 +52,7 @@ #include "spaces/jolt_job_system.h" #include "spaces/jolt_physics_direct_space_state_3d.h" #include "spaces/jolt_space_3d.h" +#include "spaces/jolt_temp_allocator.h" JoltPhysicsServer3D::JoltPhysicsServer3D(bool p_on_separate_thread) : on_separate_thread(p_on_separate_thread) { @@ -181,7 +182,7 @@ real_t JoltPhysicsServer3D::shape_get_custom_solver_bias(RID p_shape) const { } RID JoltPhysicsServer3D::space_create() { - JoltSpace3D *space = memnew(JoltSpace3D(job_system)); + JoltSpace3D *space = memnew(JoltSpace3D(job_system, temp_allocator)); RID rid = space_owner.make_rid(space); space->set_rid(rid); @@ -1605,9 +1606,15 @@ void JoltPhysicsServer3D::set_active(bool p_active) { void JoltPhysicsServer3D::init() { job_system = new JoltJobSystem(); + temp_allocator = new JoltTempAllocator(); } void JoltPhysicsServer3D::finish() { + if (temp_allocator != nullptr) { + delete temp_allocator; + temp_allocator = nullptr; + } + if (job_system != nullptr) { delete job_system; job_system = nullptr; diff --git a/modules/jolt_physics/jolt_physics_server_3d.h b/modules/jolt_physics/jolt_physics_server_3d.h index f29d97a9fe..a8db19b899 100644 --- a/modules/jolt_physics/jolt_physics_server_3d.h +++ b/modules/jolt_physics/jolt_physics_server_3d.h @@ -40,6 +40,7 @@ class JoltJoint3D; class JoltShape3D; class JoltSoftBody3D; class JoltSpace3D; +class JoltTempAllocator; class JoltPhysicsServer3D final : public PhysicsServer3D { GDCLASS(JoltPhysicsServer3D, PhysicsServer3D) @@ -56,6 +57,7 @@ class JoltPhysicsServer3D final : public PhysicsServer3D { HashSet active_spaces; JoltJobSystem *job_system = nullptr; + JoltTempAllocator *temp_allocator = nullptr; bool on_separate_thread = false; bool active = true; diff --git a/modules/jolt_physics/spaces/jolt_space_3d.cpp b/modules/jolt_physics/spaces/jolt_space_3d.cpp index 2ea9fb90bc..74d80951b1 100644 --- a/modules/jolt_physics/spaces/jolt_space_3d.cpp +++ b/modules/jolt_physics/spaces/jolt_space_3d.cpp @@ -42,7 +42,6 @@ #include "jolt_contact_listener_3d.h" #include "jolt_layers.h" #include "jolt_physics_direct_space_state_3d.h" -#include "jolt_temp_allocator.h" #include "core/io/file_access.h" #include "core/os/time.h" @@ -106,9 +105,9 @@ void JoltSpace3D::_post_step(float p_step) { } } -JoltSpace3D::JoltSpace3D(JPH::JobSystem *p_job_system) : +JoltSpace3D::JoltSpace3D(JPH::JobSystem *p_job_system, JPH::TempAllocator *p_temp_allocator) : job_system(p_job_system), - temp_allocator(new JoltTempAllocator()), + temp_allocator(p_temp_allocator), layers(new JoltLayers()), contact_listener(new JoltContactListener3D(this)), body_activation_listener(new JoltBodyActivationListener3D()), @@ -182,11 +181,6 @@ JoltSpace3D::~JoltSpace3D() { delete layers; layers = nullptr; } - - if (temp_allocator != nullptr) { - delete temp_allocator; - temp_allocator = nullptr; - } } void JoltSpace3D::step(float p_step) { diff --git a/modules/jolt_physics/spaces/jolt_space_3d.h b/modules/jolt_physics/spaces/jolt_space_3d.h index 30bd528c3a..d78b4071e1 100644 --- a/modules/jolt_physics/spaces/jolt_space_3d.h +++ b/modules/jolt_physics/spaces/jolt_space_3d.h @@ -85,7 +85,7 @@ class JoltSpace3D { void _post_step(float p_step); public: - explicit JoltSpace3D(JPH::JobSystem *p_job_system); + explicit JoltSpace3D(JPH::JobSystem *p_job_system, JPH::TempAllocator *p_temp_allocator); ~JoltSpace3D(); void step(float p_step);