Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-08-03 14:43:24 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-08-03 14:43:42 +0300
commit0342fb5d20cd13b495a7511ccfdfc3044d83cb04 (patch)
treeb1ee5f64b75c5f071999496daa7e2e4819627d2c /source/blender/blenlib/intern
parentdbd34a5acb3d0be2bdbad54a427153de49e47f8e (diff)
Fix T90387: division by zero when trying to invert scale
Fix division by zero when `BKE_bone_parent_transform_invert()` inverts a scale vector with zero components. Zero values in the to-be-inverted vector are now simply skipped, i.e. remain zero after inversion. This at least ensures that `invert_v3_safe(invert_v3_safe(vector))` results in the same vector. This commit does NOT fix the conceptual problem that an inversion of a potentially non-invertible vector is relied upon. It just avoids the division by zero.
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 55f7a152b83..dddefd60b1b 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -847,6 +847,19 @@ MINLINE void invert_v3(float r[3])
r[2] = 1.0f / r[2];
}
+MINLINE void invert_v3_safe(float r[3])
+{
+ if (r[0] != 0.0f) {
+ r[0] = 1.0f / r[0];
+ }
+ if (r[1] != 0.0f) {
+ r[1] = 1.0f / r[1];
+ }
+ if (r[2] != 0.0f) {
+ r[2] = 1.0f / r[2];
+ }
+}
+
MINLINE void abs_v2(float r[2])
{
r[0] = fabsf(r[0]);