diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-05-11 18:39:33 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-05-11 18:40:50 +0300 |
commit | 725a088ef9fce540069b19e9b1346c3d04056f8b (patch) | |
tree | dac50b9b248eab6f699ac1d5a3023b364308dc58 | |
parent | 79d01de6b06223c769f41a898652100cfd4d8b67 (diff) |
Correct check for tree being in BVH cache
-rw-r--r-- | source/blender/blenkernel/BKE_bvhutils.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/bvhutils.c | 12 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_snap_object.c | 3 |
3 files changed, 14 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index b74d653d01b..7bd3ca88076 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 37392601b4b..88be7328492 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 d01513f2064..2d7629604b1 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); - } } } |