Fix recent issue in recent BVH snap/cache

The derivedMesh could free a tree stored by the cache.
Now check the cached tree is valid.
This commit is contained in:
Campbell Barton 2016-05-07 02:59:19 +10:00
parent 9c6f33c405
commit ddbc351dd3
1 changed files with 9 additions and 0 deletions

View File

@ -33,6 +33,7 @@
#include "BLI_kdopbvh.h"
#include "BLI_memarena.h"
#include "BLI_ghash.h"
#include "BLI_linklist.h"
#include "BLI_utildefines.h"
#include "DNA_armature_types.h"
@ -659,6 +660,14 @@ static bool snapDerivedMesh(
sod->bvh_trees[tree_index] = BLI_memarena_calloc(sctx->cache.mem_arena, sizeof(*treedata));
}
treedata = sod->bvh_trees[tree_index];
/* 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) {
free_bvhtree_from_mesh(treedata);
}
}
}
}
else {