Commit: 2b946f42970bf4f3b8ce8e5c9b79451745309d89
Author: Campbell Barton
Date:   Tue Nov 19 14:31:26 2013 +1100
http://developer.blender.org/rB2b946f42970bf4f3b8ce8e5c9b79451745309d89

Fix T37445: Crash with snapping and shrink-wrap modifier.

Developer note:
BVHTREE_FROM_FACES was being used for both edit-mesh and derived-mesh
bvh-trees, this could cause index lookup errors in editmode.
Fix by adding a new type for editmesh so theres no confusion.

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

M       source/blender/blenkernel/BKE_bvhutils.h
M       source/blender/blenkernel/intern/bvhutils.c

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

diff --git a/source/blender/blenkernel/BKE_bvhutils.h 
b/source/blender/blenkernel/BKE_bvhutils.h
index 8d4c9e7..9e1bca4 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -116,6 +116,8 @@ float nearest_point_in_tri_surface(const float v0[3], const 
float v1[3], const f
 #define BVHTREE_FROM_VERTICES   1
 #define BVHTREE_FROM_EDGES      2
 
+#define BVHTREE_FROM_FACES_EDITMESH  3
+
 typedef struct LinkNode *BVHCache;
 
 
diff --git a/source/blender/blenkernel/intern/bvhutils.c 
b/source/blender/blenkernel/intern/bvhutils.c
index dba7a29..cce511a 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -573,8 +573,9 @@ BVHTree *bvhtree_from_mesh_verts(BVHTreeFromMesh *data, 
DerivedMesh *dm, float e
 /* Builds a bvh tree.. where nodes are the faces of the given dm. */
 BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, DerivedMesh *dm, float 
epsilon, int tree_type, int axis)
 {
-       BVHTree *tree = bvhcache_find(&dm->bvhCache, BVHTREE_FROM_FACES);
        BMEditMesh *em = data->em_evil;
+       const int bvhcache_type = em ? BVHTREE_FROM_FACES_EDITMESH : 
BVHTREE_FROM_FACES;
+       BVHTree *tree = bvhcache_find(&dm->bvhCache, bvhcache_type);
 
        /* Not in cache */
        if (tree == NULL) {
@@ -682,7 +683,7 @@ BVHTree *bvhtree_from_mesh_faces(BVHTreeFromMesh *data, 
DerivedMesh *dm, float e
 
                                /* Save on cache for later use */
 //                             printf("BVHTree built and saved on cache\n");
-                               bvhcache_insert(&dm->bvhCache, tree, 
BVHTREE_FROM_FACES);
+                               bvhcache_insert(&dm->bvhCache, tree, 
bvhcache_type);
                        }
                }
        }

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

Reply via email to