Merge pull request #102726 from mihe/jolt/thread-safe-errors

Skip `Object::to_string` when Jolt Physics is on separate thread
This commit is contained in:
Rémi Verschelde 2025-02-11 23:59:40 +01:00
commit 9ac02ccbcb
5 changed files with 10 additions and 8 deletions

View file

@ -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);

View file

@ -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 = "<unknown>";
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() : "<unknown>";
return instance != nullptr ? instance->to_string() : fallback_name;
}

View file

@ -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() : "<unknown>";
}

View file

@ -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