Skip to content

Commit 1006fa9

Browse files
committed
Skip Object::to_string when Jolt Physics is on separate thread
1 parent 5da6dea commit 1006fa9

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

doc/classes/ProjectSettings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@
23302330
</member>
23312331
<member name="physics/3d/run_on_separate_thread" type="bool" setter="" getter="" default="false">
23322332
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.
2333+
[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]&lt;unknown&gt;[/code].
23332334
</member>
23342335
<member name="physics/3d/sleep_threshold_angular" type="float" setter="" getter="" default="0.139626">
23352336
Threshold angular velocity under which a 3D physics body will be considered inactive. See [constant PhysicsServer3D.SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD].

modules/jolt_physics/jolt_physics_server_3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class JoltPhysicsServer3D final : public PhysicsServer3D {
421421

422422
virtual int get_process_info(PhysicsServer3D::ProcessInfo p_process_info) override;
423423

424+
bool is_on_separate_thread() const { return on_separate_thread; }
424425
bool is_active() const { return active; }
425426

426427
void free_space(JoltSpace3D *p_space);

modules/jolt_physics/objects/jolt_object_3d.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "jolt_object_3d.h"
3232

33+
#include "../jolt_physics_server_3d.h"
3334
#include "../jolt_project_settings.h"
3435
#include "../spaces/jolt_layers.h"
3536
#include "../spaces/jolt_space_3d.h"
@@ -137,6 +138,12 @@ bool JoltObject3D::can_interact_with(const JoltObject3D &p_other) const {
137138
}
138139

139140
String JoltObject3D::to_string() const {
141+
static const String fallback_name = "<unknown>";
142+
143+
if (JoltPhysicsServer3D::get_singleton()->is_on_separate_thread()) {
144+
return fallback_name; // Calling `Object::to_string` is not thread-safe.
145+
}
146+
140147
Object *instance = get_instance();
141-
return instance != nullptr ? instance->to_string() : "<unknown>";
148+
return instance != nullptr ? instance->to_string() : fallback_name;
142149
}

modules/jolt_physics/objects/jolt_soft_body_3d.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,3 @@ bool JoltSoftBody3D::is_vertex_pinned(int p_index) const {
727727

728728
return pinned_vertices.has(physics_index);
729729
}
730-
731-
String JoltSoftBody3D::to_string() const {
732-
Object *instance = get_instance();
733-
return instance != nullptr ? instance->to_string() : "<unknown>";
734-
}

modules/jolt_physics/objects/jolt_soft_body_3d.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ class JoltSoftBody3D final : public JoltObject3D {
167167
void unpin_all_vertices();
168168

169169
bool is_vertex_pinned(int p_index) const;
170-
171-
String to_string() const;
172170
};
173171

174172
#endif // JOLT_SOFT_BODY_3D_H

0 commit comments

Comments
 (0)