diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 94c2185c8f5..9c9c6d6f5cf 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2332,6 +2332,7 @@ If [code]true[/code], the 3D physics server runs on a separate thread, making better use of multi-core CPUs. If [code]false[/code], the 3D physics server runs on the main thread. Running the physics server on a separate thread can increase performance, but restricts API access to only physics process. + [b]Note:[/b] When [member physics/3d/physics_engine] is set to [code]Jolt Physics[/code], enabling this setting will prevent the 3D physics server from being able to provide any context when reporting errors and warnings, and will instead always refer to nodes as [code]<unknown>[/code]. Threshold angular velocity under which a 3D physics body will be considered inactive. See [constant PhysicsServer3D.SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD]. diff --git a/modules/jolt_physics/jolt_physics_server_3d.h b/modules/jolt_physics/jolt_physics_server_3d.h index 7dac7610f71..416e3df56ae 100644 --- a/modules/jolt_physics/jolt_physics_server_3d.h +++ b/modules/jolt_physics/jolt_physics_server_3d.h @@ -421,6 +421,7 @@ public: virtual int get_process_info(PhysicsServer3D::ProcessInfo p_process_info) override; + bool is_on_separate_thread() const { return on_separate_thread; } bool is_active() const { return active; } void free_space(JoltSpace3D *p_space); diff --git a/modules/jolt_physics/objects/jolt_object_3d.cpp b/modules/jolt_physics/objects/jolt_object_3d.cpp index 1c2019d9fa3..e9e6d504e0e 100644 --- a/modules/jolt_physics/objects/jolt_object_3d.cpp +++ b/modules/jolt_physics/objects/jolt_object_3d.cpp @@ -30,6 +30,7 @@ #include "jolt_object_3d.h" +#include "../jolt_physics_server_3d.h" #include "../jolt_project_settings.h" #include "../spaces/jolt_layers.h" #include "../spaces/jolt_space_3d.h" @@ -137,6 +138,12 @@ bool JoltObject3D::can_interact_with(const JoltObject3D &p_other) const { } String JoltObject3D::to_string() const { + static const String fallback_name = ""; + + if (JoltPhysicsServer3D::get_singleton()->is_on_separate_thread()) { + return fallback_name; // Calling `Object::to_string` is not thread-safe. + } + Object *instance = get_instance(); - return instance != nullptr ? instance->to_string() : ""; + return instance != nullptr ? instance->to_string() : fallback_name; } diff --git a/modules/jolt_physics/objects/jolt_soft_body_3d.cpp b/modules/jolt_physics/objects/jolt_soft_body_3d.cpp index 281591af9a6..040d98dace9 100644 --- a/modules/jolt_physics/objects/jolt_soft_body_3d.cpp +++ b/modules/jolt_physics/objects/jolt_soft_body_3d.cpp @@ -727,8 +727,3 @@ bool JoltSoftBody3D::is_vertex_pinned(int p_index) const { return pinned_vertices.has(physics_index); } - -String JoltSoftBody3D::to_string() const { - Object *instance = get_instance(); - return instance != nullptr ? instance->to_string() : ""; -} diff --git a/modules/jolt_physics/objects/jolt_soft_body_3d.h b/modules/jolt_physics/objects/jolt_soft_body_3d.h index f236310f6c6..4d7eb039426 100644 --- a/modules/jolt_physics/objects/jolt_soft_body_3d.h +++ b/modules/jolt_physics/objects/jolt_soft_body_3d.h @@ -167,8 +167,6 @@ public: void unpin_all_vertices(); bool is_vertex_pinned(int p_index) const; - - String to_string() const; }; #endif // JOLT_SOFT_BODY_3D_H