[Bf-blender-cvs] [725a088] master: Correct check for tree being in BVH cache

Campbell Barton noreply at git.blender.org
Wed May 11 17:35:08 CEST 2016


Commit: 725a088ef9fce540069b19e9b1346c3d04056f8b
Author: Campbell Barton
Date:   Thu May 12 01:39:33 2016 +1000
Branches: master
https://developer.blender.org/rB725a088ef9fce540069b19e9b1346c3d04056f8b

Correct check for tree being in BVH cache

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

M	source/blender/blenkernel/BKE_bvhutils.h
M	source/blender/blenkernel/intern/bvhutils.c
M	source/blender/editors/transform/transform_snap_object.c

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

diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h
index b74d653..7bd3ca8 100644
--- a/source/blender/blenkernel/BKE_bvhutils.h
+++ b/source/blender/blenkernel/BKE_bvhutils.h
@@ -184,6 +184,7 @@ enum {
 typedef struct LinkNode BVHCache;
 
 BVHTree *bvhcache_find(BVHCache *cache, int type);
+bool     bvhcache_has_tree(const BVHCache *cache, const BVHTree *tree);
 void     bvhcache_insert(BVHCache **cache_p, BVHTree *tree, int type);
 void     bvhcache_init(BVHCache **cache_p);
 void     bvhcache_free(BVHCache **cache_p);
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index 3739260..88be732 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -1162,6 +1162,18 @@ BVHTree *bvhcache_find(BVHCache *cache, int type)
 	return NULL;
 }
 
+bool bvhcache_has_tree(const BVHCache *cache, const BVHTree *tree)
+{
+	while (cache) {
+		const BVHCacheItem *item = cache->link;
+		if (item->tree == tree) {
+			return true;
+		}
+		cache = cache->next;
+	}
+	return false;
+}
+
 /**
  * Inserts a BVHTree of the given type under the cache
  * After that the caller no longer needs to worry when to free the BVHTree
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index d01513f..2d76296 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -786,9 +786,8 @@ static bool snapDerivedMesh(
 
 				/* the tree is owned by the DM and may have been freed since we last used! */
 				if (treedata && treedata->tree) {
-					if (BLI_linklist_index(dm->bvhCache, treedata->tree) == -1) {
+					if (treedata->cached && !bvhcache_has_tree(&dm->bvhCache, treedata->tree)) {
 						free_bvhtree_from_mesh(treedata);
-
 					}
 				}
 			}




More information about the Bf-blender-cvs mailing list