diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-11-12 09:27:57 -0600 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-11-12 09:27:57 -0600 |
commit | 1af1bb7d609f2c0d63832e807e9b9014c007dc71 (patch) | |
tree | 1f5101642b0cebf9ae369ccff547ad90743b70e5 | |
parent | b85a4752cca2f2471161f43e0b79942878bb3a1b (diff) | |
parent | 33afdff08dfe31aac5895d1541c74ef9bfadf1e2 (diff) | |
download | redot-engine-1af1bb7d609f2c0d63832e807e9b9014c007dc71.tar.gz |
Merge pull request #98625 from jweisberg/handle-nan-in-curve3d-find-interval
Curve: Check for finiteness before performing calculations in `sample_baked()` functions
-rw-r--r-- | scene/resources/curve.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index 8926eb1d51..765373ce99 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -479,6 +479,9 @@ void Curve::set_bake_resolution(int p_resolution) { } real_t Curve::sample_baked(real_t p_offset) const { + // Make sure that p_offset is finite. + ERR_FAIL_COND_V_MSG(!Math::is_finite(p_offset), 0, "Offset is non-finite"); + if (_baked_cache_dirty) { // Last-second bake if not done already const_cast<Curve *>(this)->bake(); @@ -981,6 +984,9 @@ Transform2D Curve2D::_sample_posture(Interval p_interval) const { } Vector2 Curve2D::sample_baked(real_t p_offset, bool p_cubic) const { + // Make sure that p_offset is finite. + ERR_FAIL_COND_V_MSG(!Math::is_finite(p_offset), Vector2(), "Offset is non-finite"); + if (baked_cache_dirty) { _bake(); } @@ -1000,6 +1006,9 @@ Vector2 Curve2D::sample_baked(real_t p_offset, bool p_cubic) const { } Transform2D Curve2D::sample_baked_with_rotation(real_t p_offset, bool p_cubic) const { + // Make sure that p_offset is finite. + ERR_FAIL_COND_V_MSG(!Math::is_finite(p_offset), Transform2D(), "Offset is non-finite"); + if (baked_cache_dirty) { _bake(); } @@ -1881,6 +1890,9 @@ Basis Curve3D::get_point_baked_posture(int p_index, bool p_apply_tilt) const { #endif Vector3 Curve3D::sample_baked(real_t p_offset, bool p_cubic) const { + // Make sure that p_offset is finite. + ERR_FAIL_COND_V_MSG(!Math::is_finite(p_offset), Vector3(), "Offset is non-finite"); + if (baked_cache_dirty) { _bake(); } @@ -1900,6 +1912,9 @@ Vector3 Curve3D::sample_baked(real_t p_offset, bool p_cubic) const { } Transform3D Curve3D::sample_baked_with_rotation(real_t p_offset, bool p_cubic, bool p_apply_tilt) const { + // Make sure that p_offset is finite. + ERR_FAIL_COND_V_MSG(!Math::is_finite(p_offset), Transform3D(), "Offset is non-finite"); + if (baked_cache_dirty) { _bake(); } @@ -1929,6 +1944,9 @@ Transform3D Curve3D::sample_baked_with_rotation(real_t p_offset, bool p_cubic, b } real_t Curve3D::sample_baked_tilt(real_t p_offset) const { + // Make sure that p_offset is finite. + ERR_FAIL_COND_V_MSG(!Math::is_finite(p_offset), 0, "Offset is non-finite"); + if (baked_cache_dirty) { _bake(); } @@ -1948,6 +1966,9 @@ real_t Curve3D::sample_baked_tilt(real_t p_offset) const { } Vector3 Curve3D::sample_baked_up_vector(real_t p_offset, bool p_apply_tilt) const { + // Make sure that p_offset is finite. + ERR_FAIL_COND_V_MSG(!Math::is_finite(p_offset), Vector3(0, 1, 0), "Offset is non-finite"); + if (baked_cache_dirty) { _bake(); } |