Skip to content

Commit

Permalink
add some BVH-related assertions and sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Apr 21, 2024
1 parent 4ff1a71 commit 2d01457
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,16 @@ private void createShape() {
setScale(scale);
setMargin(margin);

assert !hasBvh(shapeId);
if (bvh == null) {
this.bvh = new BoundingValueHierarchy(this);
} else {
long bvhId = bvh.nativeId();
setOptimizedBvh(shapeId, bvhId, scale);
}
assert hasBvh(shapeId);
assert bvh.isCompressed() == useCompression :
bvh.isCompressed() + " != " + useCompression;
}
// *************************************************************************
// native private methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,17 @@ btQuantizedBvh
{
return m_useQuantization;
}
void checkSanity() const // stephengold added 2024-04-20
{ // stephengold added 2024-04-20
btAssert(m_bulletVersion == BT_BULLET_VERSION); // stephengold added 2024-04-20
btAssert(m_traversalMode == TRAVERSAL_STACKLESS || // stephengold added 2024-04-20
m_traversalMode == TRAVERSAL_STACKLESS_CACHE_FRIENDLY || // stephengold added 2024-04-20
m_traversalMode == TRAVERSAL_RECURSIVE); // stephengold added 2024-04-20
btAssert(m_bvhAabbMin.x() <= m_bvhAabbMax.x()); // stephengold added 2024-04-20
btAssert(m_bvhAabbMin.y() <= m_bvhAabbMax.y()); // stephengold added 2024-04-20
btAssert(m_bvhAabbMin.z() <= m_bvhAabbMax.z()); // stephengold added 2024-04-20
btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size()); // stephengold added 2024-04-20
} // stephengold added 2024-04-20

private:
// Special "copy" constructor that allows for in-place deserialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_infos_BoundingValu
jlong id2 = reinterpret_cast<jlong> (pBuffer);
btAssert(id1 == id2);

pBvh->checkSanity();

return id1;
}

Expand All @@ -76,6 +78,8 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_shapes_infos_BoundingValue
const btOptimizedBvh * const
pBvh = reinterpret_cast<btOptimizedBvh *> (bvhId);
NULL_CHK(pEnv, pBvh, "The btOptimizedBvh does not exist.",);
pBvh->checkSanity();

pBvh->~btOptimizedBvh();

void *pBuffer = reinterpret_cast<void *> (bvhId);
Expand All @@ -98,7 +102,9 @@ JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_infos_BoundingValu
if (pBvh == NULL) {
pShape->buildOptimizedBvh();
pBvh = pShape->getOptimizedBvh();
btAssert(pBvh);
}
pBvh->checkSanity();

return reinterpret_cast<jlong> (pBvh);
}
Expand All @@ -113,6 +119,7 @@ JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_collision_shapes_infos_BoundingV
const btOptimizedBvh * const
pBvh = reinterpret_cast<btOptimizedBvh *> (bvhId);
NULL_CHK(pEnv, pBvh, "The btOptimizedBvh does not exist.", JNI_FALSE);
pBvh->checkSanity();

bool result = pBvh->isQuantized();
return result;
Expand All @@ -128,6 +135,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_jme3_bullet_collision_shapes_infos_Boundin
const btOptimizedBvh * const
pBvh = reinterpret_cast<btOptimizedBvh *> (bvhId);
NULL_CHK(pEnv, pBvh, "The btOptimizedBvh does not exist.", 0);
pBvh->checkSanity();

unsigned int bufferSize = pBvh->calculateSerializeBufferSize();
char *pBuffer = (char *) btAlignedAlloc(bufferSize, 16); //dance015
Expand Down

0 comments on commit 2d01457

Please sign in to comment.