From 5a0a909a01eee47eb0a9e98cfc09092bebec93c3 Mon Sep 17 00:00:00 2001 From: Omar Elhamedy Date: Thu, 9 May 2024 02:25:30 +0300 Subject: [PATCH 1/3] Validate Deque mBuffer before releasing the chunks array added validation to check the mBuffer is not nulltpr and the mCapacity isn't zero before calling mAllocator.release, this prevent crash on calling the destructor on empty buffer --- include/reactphysics3d/containers/Deque.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/reactphysics3d/containers/Deque.h b/include/reactphysics3d/containers/Deque.h index 7658c1b5..ae05747e 100644 --- a/include/reactphysics3d/containers/Deque.h +++ b/include/reactphysics3d/containers/Deque.h @@ -296,8 +296,10 @@ class Deque { clear(); - // Release the chunks array - mAllocator.release(mBuffer, sizeof(T) * mCapacity); + if (mBuffer != nullptr && mCapacity == 0) { + // Release the chunks array + mAllocator.release(mBuffer, sizeof(T) * mCapacity); + } mCapacity = 0; mBuffer = nullptr; From 95cc12d6016ffa85bda1fd8887d0afb01858ea77 Mon Sep 17 00:00:00 2001 From: Omar Elhamedy Date: Thu, 9 May 2024 02:29:58 +0300 Subject: [PATCH 2/3] updated validation --- include/reactphysics3d/containers/Deque.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/reactphysics3d/containers/Deque.h b/include/reactphysics3d/containers/Deque.h index ae05747e..71abd2e4 100644 --- a/include/reactphysics3d/containers/Deque.h +++ b/include/reactphysics3d/containers/Deque.h @@ -296,7 +296,7 @@ class Deque { clear(); - if (mBuffer != nullptr && mCapacity == 0) { + if (mBuffer != nullptr && mCapacity > 0) { // Release the chunks array mAllocator.release(mBuffer, sizeof(T) * mCapacity); } From 6fc73c15434037f60de759243fbf57b23da938f2 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Fri, 31 May 2024 07:47:11 +0200 Subject: [PATCH 3/3] Edit fix for the assert when destroying an empty PhysicsWorld --- CHANGELOG.md | 1 + include/reactphysics3d/containers/Deque.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab69d18a..9af6a45a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixed +- Issue [#377](https://github.com/DanielChappuis/reactphysics3d/issues/377) Fix assert when destroying an empty PhysicsWorld - Issue [#378](https://github.com/DanielChappuis/reactphysics3d/issues/378) Fix issue with raycasting of HeightFieldShape - Fix crash within testbed application in raycasting scene diff --git a/include/reactphysics3d/containers/Deque.h b/include/reactphysics3d/containers/Deque.h index 71abd2e4..2a7977b1 100644 --- a/include/reactphysics3d/containers/Deque.h +++ b/include/reactphysics3d/containers/Deque.h @@ -296,7 +296,10 @@ class Deque { clear(); - if (mBuffer != nullptr && mCapacity > 0) { + if (mCapacity > 0) { + + assert(mBuffer != nullptr); + // Release the chunks array mAllocator.release(mBuffer, sizeof(T) * mCapacity); }