From 2d01457d7dbd9f0a2f65ba2b18b7b3cb8b0ac018 Mon Sep 17 00:00:00 2001 From: Stephen Gold Date: Sat, 20 Apr 2024 22:33:02 -0700 Subject: [PATCH] add some BVH-related assertions and sanity checks --- .../bullet/collision/shapes/MeshCollisionShape.java | 4 ++++ .../BroadphaseCollision/btQuantizedBvh.h | 11 +++++++++++ ..._collision_shapes_infos_BoundingValueHierarchy.cpp | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java b/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java index 2bab64b7..e682532e 100644 --- a/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java +++ b/src/main/java/com/jme3/bullet/collision/shapes/MeshCollisionShape.java @@ -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 diff --git a/src/main/native/bullet3/BulletCollision/BroadphaseCollision/btQuantizedBvh.h b/src/main/native/bullet3/BulletCollision/BroadphaseCollision/btQuantizedBvh.h index 648bc6a1..5532d08f 100644 --- a/src/main/native/bullet3/BulletCollision/BroadphaseCollision/btQuantizedBvh.h +++ b/src/main/native/bullet3/BulletCollision/BroadphaseCollision/btQuantizedBvh.h @@ -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 diff --git a/src/main/native/glue/com_jme3_bullet_collision_shapes_infos_BoundingValueHierarchy.cpp b/src/main/native/glue/com_jme3_bullet_collision_shapes_infos_BoundingValueHierarchy.cpp index c0a80744..7176c9d6 100644 --- a/src/main/native/glue/com_jme3_bullet_collision_shapes_infos_BoundingValueHierarchy.cpp +++ b/src/main/native/glue/com_jme3_bullet_collision_shapes_infos_BoundingValueHierarchy.cpp @@ -63,6 +63,8 @@ JNIEXPORT jlong JNICALL Java_com_jme3_bullet_collision_shapes_infos_BoundingValu jlong id2 = reinterpret_cast (pBuffer); btAssert(id1 == id2); + pBvh->checkSanity(); + return id1; } @@ -76,6 +78,8 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_collision_shapes_infos_BoundingValue const btOptimizedBvh * const pBvh = reinterpret_cast (bvhId); NULL_CHK(pEnv, pBvh, "The btOptimizedBvh does not exist.",); + pBvh->checkSanity(); + pBvh->~btOptimizedBvh(); void *pBuffer = reinterpret_cast (bvhId); @@ -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 (pBvh); } @@ -113,6 +119,7 @@ JNIEXPORT jboolean JNICALL Java_com_jme3_bullet_collision_shapes_infos_BoundingV const btOptimizedBvh * const pBvh = reinterpret_cast (bvhId); NULL_CHK(pEnv, pBvh, "The btOptimizedBvh does not exist.", JNI_FALSE); + pBvh->checkSanity(); bool result = pBvh->isQuantized(); return result; @@ -128,6 +135,7 @@ JNIEXPORT jbyteArray JNICALL Java_com_jme3_bullet_collision_shapes_infos_Boundin const btOptimizedBvh * const pBvh = reinterpret_cast (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