BLI_kdopbvh: assert for bad input

also hint UNLIKELY branches
This commit is contained in:
Campbell Barton 2014-07-16 11:11:18 +10:00
parent 1ae11f71ff
commit b26daac398
2 changed files with 16 additions and 12 deletions

@ -1039,7 +1039,7 @@ static void traverse(BVHOverlapData *data, BVHNode *node1, BVHNode *node2)
if (!node2->totnode) { if (!node2->totnode) {
BVHTreeOverlap *overlap; BVHTreeOverlap *overlap;
if (node1 == node2) { if (UNLIKELY(node1 == node2)) {
return; return;
} }
@ -1073,8 +1073,13 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int
BVHOverlapData **data; BVHOverlapData **data;
/* check for compatibility of both trees (can't compare 14-DOP with 18-DOP) */ /* check for compatibility of both trees (can't compare 14-DOP with 18-DOP) */
if ((tree1->axis != tree2->axis) && (tree1->axis == 14 || tree2->axis == 14) && (tree1->axis == 18 || tree2->axis == 18)) if (UNLIKELY((tree1->axis != tree2->axis) &&
(tree1->axis == 14 || tree2->axis == 14) &&
(tree1->axis == 18 || tree2->axis == 18)))
{
BLI_assert(0);
return NULL; return NULL;
}
/* fast check root nodes for collision before doing big splitting + traversal */ /* fast check root nodes for collision before doing big splitting + traversal */
if (!tree_overlap(tree1->nodes[tree1->totleaf], tree2->nodes[tree2->totleaf], if (!tree_overlap(tree1->nodes[tree1->totleaf], tree2->nodes[tree2->totleaf],
@ -1084,10 +1089,10 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int
return NULL; return NULL;
} }
data = MEM_callocN(sizeof(BVHOverlapData *) * tree1->tree_type, "BVHOverlapData_star"); data = MEM_mallocN(sizeof(BVHOverlapData *) * tree1->tree_type, "BVHOverlapData_star");
for (j = 0; j < tree1->tree_type; j++) { for (j = 0; j < tree1->tree_type; j++) {
data[j] = MEM_callocN(sizeof(BVHOverlapData), "BVHOverlapData"); data[j] = MEM_mallocN(sizeof(BVHOverlapData), "BVHOverlapData");
/* init BVHOverlapData */ /* init BVHOverlapData */
data[j]->overlap = BLI_stack_new(sizeof(BVHTreeOverlap), __func__); data[j]->overlap = BLI_stack_new(sizeof(BVHTreeOverlap), __func__);
@ -1159,13 +1164,6 @@ static float calc_nearest_point_squared(const float proj[3], BVHNode *node, floa
return len_squared_v3v3(proj, nearest); return len_squared_v3v3(proj, nearest);
} }
typedef struct NodeDistance {
BVHNode *node;
float dist;
} NodeDistance;
/* TODO: use a priority queue to reduce the number of nodes looked on */ /* TODO: use a priority queue to reduce the number of nodes looked on */
static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node)
{ {
@ -1213,6 +1211,12 @@ static void dfs_find_nearest_begin(BVHNearestData *data, BVHNode *node)
#if 0 #if 0
typedef struct NodeDistance {
BVHNode *node;
float dist;
} NodeDistance;
#define DEFAULT_FIND_NEAREST_HEAP_SIZE 1024 #define DEFAULT_FIND_NEAREST_HEAP_SIZE 1024
#define NodeDistance_priority(a, b) ((a).dist < (b).dist) #define NodeDistance_priority(a, b) ((a).dist < (b).dist)

@ -185,7 +185,7 @@ void BLI_stack_pop(BLI_Stack *stack, void *dst)
#ifdef USE_TOTELEM #ifdef USE_TOTELEM
stack->totelem--; stack->totelem--;
#endif #endif
if (--stack->chunk_index == CHUNK_EMPTY) { if (UNLIKELY(--stack->chunk_index == CHUNK_EMPTY)) {
struct StackChunk *chunk_free; struct StackChunk *chunk_free;
chunk_free = stack->chunk_curr; chunk_free = stack->chunk_curr;