Commit: 7b6d09e9bd94ca4e28441632733d4077a2f27b1c
Author: Luca Rood
Date:   Sun Feb 12 01:48:10 2017 -0200
Branches: cloth-improvements
https://developer.blender.org/rB7b6d09e9bd94ca4e28441632733d4077a2f27b1c

Fix stack overflow in spring angle calculation

===================================================================

M       source/blender/blenkernel/intern/cloth.c
M       source/blender/physics/intern/implicit_blender.c

===================================================================

diff --git a/source/blender/blenkernel/intern/cloth.c 
b/source/blender/blenkernel/intern/cloth.c
index bcb979e656..23b9fb5dc2 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -960,24 +960,25 @@ BLI_INLINE float spring_angle(ClothVertex *verts, int i, 
int j, int *i_a, int *i
        float dir_a[3], dir_b[3];
        float tmp1[3], tmp2[3], vec_e[3];
        float sin, cos;
-       float (*array_a)[3] = BLI_array_alloca(array_a, len_a);
-       float (*array_b)[3] = BLI_array_alloca(array_b, len_b);
+       float fact_a = 1.0f / len_a;
+       float fact_b = 1.0f / len_b;
        int x;
 
+       zero_v3(co_a);
+       zero_v3(co_b);
+
        /* assign poly vert coords to arrays */
        for (x = 0; x < len_a; x++) {
-               copy_v3_v3(array_a[x], verts[i_a[x]].xrest);
+               madd_v3_v3fl(co_a, verts[i_a[x]].xrest, fact_a);
        }
 
        for (x = 0; x < len_b; x++) {
-               copy_v3_v3(array_b[x], verts[i_b[x]].xrest);
+               madd_v3_v3fl(co_b, verts[i_b[x]].xrest, fact_b);
        }
 
        /* get edge vert coords and poly centroid coords. */
        copy_v3_v3(co_i, verts[i].xrest);
        copy_v3_v3(co_j, verts[j].xrest);
-       cent_poly_v3(co_a, array_a, len_a);
-       cent_poly_v3(co_b, array_b, len_b);
 
        /* find dir for poly a */
        sub_v3_v3v3(tmp1, co_j, co_a);
diff --git a/source/blender/physics/intern/implicit_blender.c 
b/source/blender/physics/intern/implicit_blender.c
index 2d14502d52..d38f173ced 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -1700,8 +1700,8 @@ BLI_INLINE bool spring_angle(Implicit_Data *data, int i, 
int j, int *i_a, int *i
        float co_i[3], co_j[3], co_a[3], co_b[3];
        float tmp1[3], tmp2[3], vec_e[3];
        float sin, cos;
-       float (*array_a)[3] = BLI_array_alloca(array_a, len_a);
-       float (*array_b)[3] = BLI_array_alloca(array_b, len_b);
+       float (*array_a)[3] = MEM_mallocN(sizeof(*array_a) * len_a, "spring 
angle poly a");
+       float (*array_b)[3] = MEM_mallocN(sizeof(*array_b) * len_b, "spring 
angle poly b");
        int x;
 
        /* assign poly vert coords to arrays */
@@ -1765,6 +1765,9 @@ BLI_INLINE bool spring_angle(Implicit_Data *data, int i, 
int j, int *i_a, int *i
        sub_v3_v3(r_vel_a, tmp1);
        sub_v3_v3(r_vel_b, tmp1);
 
+       MEM_freeN(array_a);
+       MEM_freeN(array_b);
+
        return true;
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to