diff --git a/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp index f58fe4c93..6edb13aea 100644 --- a/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp +++ b/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp @@ -145,25 +145,25 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const { vertex.setValue( height, - (-m_width/2 ) + x, - (-m_length/2 ) + y + (-m_width/btScalar(2.0)) + x, + (-m_length/btScalar(2.0) ) + y ); break; } case 1: { vertex.setValue( - (-m_width/2 ) + x, + (-m_width/btScalar(2.0)) + x, height, - (-m_length/2 ) + y + (-m_length/btScalar(2.0)) + y ); break; }; case 2: { vertex.setValue( - (-m_width/2 ) + x, - (-m_length/2 ) + y, + (-m_width/btScalar(2.0)) + x, + (-m_length/btScalar(2.0)) + y, height ); break; diff --git a/src/LinearMath/btAlignedAllocator.cpp b/src/LinearMath/btAlignedAllocator.cpp index 6c81b9b8e..5e49d1f2c 100644 --- a/src/LinearMath/btAlignedAllocator.cpp +++ b/src/LinearMath/btAlignedAllocator.cpp @@ -54,17 +54,33 @@ void btAlignedFree (void* ptr) } #else -///todo -///will add some multi-platform version that works without _aligned_malloc/_aligned_free void* btAlignedAlloc (int size, int alignment) { - return new char[size]; + void *ret; + char *real; + unsigned long offset; + + real = (char *)malloc(size + sizeof(void *) + (alignment-1)); + if (real) { + offset = (alignment - (unsigned long)(real + sizeof(void *))) & (alignment-1); + ret = (void *)((real + sizeof(void *)) + offset); + *((void **)(ret)-1) = (void *)(real); + } else { + ret = (void *)(real); + } + return (ret); } void btAlignedFree (void* ptr) { - delete [] (char*) ptr; + + void* real; + + if (ptr) { + real = *((void **)(ptr)-1); + free(real); + } } #endif //