diff options
-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); - } } } |