mirror of
https://github.com/bulletphysics/bullet3
synced 2025-01-10 01:20:05 +00:00
Allow properly override of btAlignedAllocSetCustomAligned
Fixes Issue 430, Thanks to wombatzus
This commit is contained in:
parent
9c7220a78d
commit
41314b5ebc
@ -160,22 +160,8 @@ void btAlignedFreeInternal (void* ptr,int line,char* filename)
|
|||||||
void* btAlignedAllocInternal (size_t size, int alignment)
|
void* btAlignedAllocInternal (size_t size, int alignment)
|
||||||
{
|
{
|
||||||
gNumAlignedAllocs++;
|
gNumAlignedAllocs++;
|
||||||
void* ptr;
|
void* ptr;
|
||||||
#if defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__)
|
|
||||||
ptr = sAlignedAllocFunc(size, alignment);
|
ptr = sAlignedAllocFunc(size, alignment);
|
||||||
#else
|
|
||||||
char *real;
|
|
||||||
unsigned long offset;
|
|
||||||
|
|
||||||
real = (char *)sAllocFunc(size + sizeof(void *) + (alignment-1));
|
|
||||||
if (real) {
|
|
||||||
offset = (alignment - (unsigned long)(real + sizeof(void *))) & (alignment-1);
|
|
||||||
ptr = (void *)((real + sizeof(void *)) + offset);
|
|
||||||
*((void **)(ptr)-1) = (void *)(real);
|
|
||||||
} else {
|
|
||||||
ptr = (void *)(real);
|
|
||||||
}
|
|
||||||
#endif // defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__)
|
|
||||||
// printf("btAlignedAllocInternal %d, %x\n",size,ptr);
|
// printf("btAlignedAllocInternal %d, %x\n",size,ptr);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
@ -189,16 +175,7 @@ void btAlignedFreeInternal (void* ptr)
|
|||||||
|
|
||||||
gNumAlignedFree++;
|
gNumAlignedFree++;
|
||||||
// printf("btAlignedFreeInternal %x\n",ptr);
|
// printf("btAlignedFreeInternal %x\n",ptr);
|
||||||
#if defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__)
|
|
||||||
sAlignedFreeFunc(ptr);
|
sAlignedFreeFunc(ptr);
|
||||||
#else
|
|
||||||
void* real;
|
|
||||||
|
|
||||||
if (ptr) {
|
|
||||||
real = *((void **)(ptr)-1);
|
|
||||||
sFreeFunc(real);
|
|
||||||
}
|
|
||||||
#endif // defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||||
|
Loading…
Reference in New Issue
Block a user