Godot Engine – Multi-platform 2D and 3D game engine
Replace `Callable::is_valid` with `is_null` in Jolt module
Mikael Hermanssona39a1d61239f
diff --git a/modules/jolt_physics/objects/jolt_area_3d.cpp b/modules/jolt_physics/objects/jolt_area_3d.cppindex 9136a0cb7ec..1aa0e7db2cf 100644--- a/modules/jolt_physics/objects/jolt_area_3d.cpp+++ b/modules/jolt_physics/objects/jolt_area_3d.cpp@@ -134,11 +134,11 @@ bool JoltArea3D::_remove_shape_pair(Overlap &p_overlap, const JPH::SubShapeID &preturn true;}-void JoltArea3D::_flush_events(OverlapsById &p_objects, const Callable &p_callback) {+void JoltArea3D::_flush_events(OverlapsById &p_objects, Callable &p_callback) {for (OverlapsById::Iterator E = p_objects.begin(); E;) {Overlap &overlap = E->value;- if (p_callback.is_valid()) {+ if (!p_callback.is_null()) {for (const ShapeIndexPair &shape_indices : overlap.pending_added) {int &ref_count = overlap.ref_counts[shape_indices];if (ref_count++ == 0) {@@ -170,8 +170,10 @@ void JoltArea3D::_flush_events(OverlapsById &p_objects, const Callable &p_callba}}-void JoltArea3D::_report_event(const Callable &p_callback, PS3DE::AreaBodyStatus p_status, const RID &p_other_rid, ObjectID p_other_instance_id, int p_other_shape_index, int p_self_shape_index) const {- ERR_FAIL_COND(!p_callback.is_valid());+void JoltArea3D::_report_event(Callable &p_callback, PS3DE::AreaBodyStatus p_status, const RID &p_other_rid, ObjectID p_other_instance_id, int p_other_shape_index, int p_self_shape_index) {+ if (unlikely(p_callback.is_null())) {+ return;+ }const Variant arg1 = p_status;const Variant arg2 = p_other_rid;@@ -185,7 +187,13 @@ void JoltArea3D::_report_event(const Callable &p_callback, PS3DE::AreaBodyStatusp_callback.callp(args, 5, ret, ce);if (unlikely(ce.error != Callable::CallError::CALL_OK)) {- ERR_PRINT_ONCE(vformat("Failed to call area monitor callback for '%s'. It returned the following error: '%s'.", to_string(), Variant::get_callable_error_text(p_callback, args, 5, ce)));+ if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) {+ // Godot Physics effectively silences this error by virtue of doing a `Callable::is_valid` check before the call, so we silently ignore this for compatibility.+ // There's no point in trying to call this callback again though, so we clear it.+ p_callback = Callable();+ } else {+ ERR_PRINT_ONCE(vformat("Failed to call area monitor callback for '%s'. It returned the following error: '%s'.", to_string(), Variant::get_callable_error_text(p_callback, args, 5, ce)));+ }}}diff --git a/modules/jolt_physics/objects/jolt_area_3d.h b/modules/jolt_physics/objects/jolt_area_3d.hindex acef0381722..9d7b13e1a1c 100644--- a/modules/jolt_physics/objects/jolt_area_3d.h+++ b/modules/jolt_physics/objects/jolt_area_3d.h@@ -137,9 +137,8 @@ private:void _add_shape_pair(Overlap &p_overlap, const JPH::BodyID &p_body_id, const JPH::SubShapeID &p_other_shape_id, const JPH::SubShapeID &p_self_shape_id);bool _remove_shape_pair(Overlap &p_overlap, const JPH::SubShapeID &p_other_shape_id, const JPH::SubShapeID &p_self_shape_id);- void _flush_events(OverlapsById &p_objects, const Callable &p_callback);-- void _report_event(const Callable &p_callback, PS3DE::AreaBodyStatus p_status, const RID &p_other_rid, ObjectID p_other_instance_id, int p_other_shape_index, int p_self_shape_index) const;+ void _flush_events(OverlapsById &p_objects, Callable &p_callback);+ void _report_event(Callable &p_callback, PS3DE::AreaBodyStatus p_status, const RID &p_other_rid, ObjectID p_other_instance_id, int p_other_shape_index, int p_self_shape_index);void _notify_body_entered(const JPH::BodyID &p_body_id);void _notify_body_exited(const JPH::BodyID &p_body_id);@@ -165,10 +164,10 @@ public:Variant get_param(PS3DE::AreaParameter p_param) const;void set_param(PS3DE::AreaParameter p_param, const Variant &p_value);- bool has_body_monitor_callback() const { return body_monitor_callback.is_valid(); }+ bool has_body_monitor_callback() const { return !body_monitor_callback.is_null(); }void set_body_monitor_callback(const Callable &p_callback);- bool has_area_monitor_callback() const { return area_monitor_callback.is_valid(); }+ bool has_area_monitor_callback() const { return !area_monitor_callback.is_null(); }void set_area_monitor_callback(const Callable &p_callback);bool is_monitoring_bodies() const { return has_body_monitor_callback(); }diff --git a/modules/jolt_physics/objects/jolt_body_3d.cpp b/modules/jolt_physics/objects/jolt_body_3d.cppindex 31511f3c19c..b26952be3ab 100644--- a/modules/jolt_physics/objects/jolt_body_3d.cpp+++ b/modules/jolt_physics/objects/jolt_body_3d.cpp@@ -1074,7 +1074,7 @@ void JoltBody3D::remove_joint(JoltJoint3D *p_joint) {}void JoltBody3D::call_queries() {- if (custom_integration_callback.is_valid()) {+ if (!custom_integration_callback.is_null()) {const Variant direct_state_variant = get_direct_state();const Variant *args[2] = { &direct_state_variant, &custom_integration_userdata };const int argc = custom_integration_userdata.get_type() != Variant::NIL ? 2 : 1;@@ -1084,11 +1084,17 @@ void JoltBody3D::call_queries() {custom_integration_callback.callp(args, argc, ret, ce);if (unlikely(ce.error != Callable::CallError::CALL_OK)) {- ERR_PRINT_ONCE(vformat("Failed to call force integration callback for '%s'. It returned the following error: '%s'.", to_string(), Variant::get_callable_error_text(custom_integration_callback, args, argc, ce)));+ if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) {+ // Godot Physics effectively silences this error by virtue of doing a `Callable::is_valid` check before the call, so we silently ignore this for compatibility.+ // There's no point in trying to call this callback again though, so we clear it.+ custom_integration_callback = Callable();+ } else {+ ERR_PRINT_ONCE(vformat("Failed to call force integration callback for '%s'. It returned the following error: '%s'.", to_string(), Variant::get_callable_error_text(custom_integration_callback, args, argc, ce)));+ }}}- if (state_sync_callback.is_valid()) {+ if (!state_sync_callback.is_null()) {const Variant direct_state_variant = get_direct_state();const Variant *args[1] = { &direct_state_variant };@@ -1097,7 +1103,13 @@ void JoltBody3D::call_queries() {state_sync_callback.callp(args, 1, ret, ce);if (unlikely(ce.error != Callable::CallError::CALL_OK)) {- ERR_PRINT_ONCE(vformat("Failed to call state synchronization callback for '%s'. It returned the following error: '%s'.", to_string(), Variant::get_callable_error_text(state_sync_callback, args, 1, ce)));+ if (ce.error == Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL) {+ // Godot Physics effectively silences this error by virtue of doing a `Callable::is_valid` check before the call, so we silently ignore this for compatibility.+ // There's no point in trying to call this callback again though, so we clear it.+ state_sync_callback = Callable();+ } else {+ ERR_PRINT_ONCE(vformat("Failed to call state synchronization callback for '%s'. It returned the following error: '%s'.", to_string(), Variant::get_callable_error_text(state_sync_callback, args, 1, ce)));+ }}}}diff --git a/modules/jolt_physics/objects/jolt_body_3d.h b/modules/jolt_physics/objects/jolt_body_3d.hindex fad4196a5c6..7c0af9100f2 100644--- a/modules/jolt_physics/objects/jolt_body_3d.h+++ b/modules/jolt_physics/objects/jolt_body_3d.h@@ -113,7 +113,7 @@ private:virtual void _add_to_space() override;- bool _should_call_queries() const { return state_sync_callback.is_valid() || custom_integration_callback.is_valid(); }+ bool _should_call_queries() const { return !state_sync_callback.is_null() || !custom_integration_callback.is_null(); }void _enqueue_call_queries();void _dequeue_call_queries();@@ -165,10 +165,10 @@ public:Variant get_param(PS3DE::BodyParameter p_param) const;void set_param(PS3DE::BodyParameter p_param, const Variant &p_value);- bool has_state_sync_callback() const { return state_sync_callback.is_valid(); }+ bool has_state_sync_callback() const { return !state_sync_callback.is_null(); }void set_state_sync_callback(const Callable &p_callback) { state_sync_callback = p_callback; }- bool has_custom_integration_callback() const { return custom_integration_callback.is_valid(); }+ bool has_custom_integration_callback() const { return !custom_integration_callback.is_null(); }void set_custom_integration_callback(const Callable &p_callback, const Variant &p_userdata) {custom_integration_callback = p_callback;custom_integration_userdata = p_userdata;