Skip to content

Commit

Permalink
[memory] Fix alignment issues
Browse files Browse the repository at this point in the history
[body] expose getWorld()
  • Loading branch information
Nicolas BOUQUET committed Aug 17, 2023
1 parent 6ea5716 commit 495f644
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/reactphysics3d/body/CollisionBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class CollisionBody {

#endif

PhysicsWorld &getWorld() { return mWorld; };
// -------------------- Friendship -------------------- //

friend class PhysicsWorld;
Expand Down
9 changes: 5 additions & 4 deletions include/reactphysics3d/memory/HeapAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ class HeapAllocator : public MemoryAllocator {
/// True if the memory unit is currently allocated
bool isAllocated;

/// True if the next memory unit has been allocated with the same call to malloc()
bool isNextContiguousMemory;

/// Pointer to the previous memory unit
MemoryUnitHeader* previousUnit;

/// Pointer to the next memory unit
MemoryUnitHeader* nextUnit;

/// True if the next memory unit has been allocated with the same call to malloc()
bool isNextContiguousMemory;

// -------------------- Methods -------------------- //

MemoryUnitHeader(size_t size, MemoryUnitHeader* previousUnit, MemoryUnitHeader* nextUnit, bool isNextContiguousMemory)
: size(size), isAllocated(false), previousUnit(previousUnit),
nextUnit(nextUnit), isNextContiguousMemory(isNextContiguousMemory) {
: size(size), isAllocated(false), isNextContiguousMemory(isNextContiguousMemory), previousUnit(previousUnit),
nextUnit(nextUnit) {

assert(size > 0);
}
Expand Down
3 changes: 3 additions & 0 deletions src/memory/HeapAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ void* HeapAllocator::allocate(size_t size) {
// We cannot allocate zero bytes
if (size == 0) return nullptr;

//Ensure allocated size is a multiple of 8
size=(size+7)&(~7);

#ifndef NDEBUG
mNbTimesAllocateMethodCalled++;
#endif
Expand Down

0 comments on commit 495f644

Please sign in to comment.