64bit compilation problems, btAlignedAllocator.cpp

User avatar
Dragonlord
Posts: 198
Joined: Mon Sep 04, 2006 5:31 pm
Location: Switzerland

64bit compilation problems, btAlignedAllocator.cpp

Post by Dragonlord »

Trying to compile bullet on 64-bit Linux seems to work fine but fails compiling on Windows 64-bit. Compiling fails here:

Code: Select all

Compiling src\modules\physics\bullet\build\Bullet\LinearMath\btAlignedAllocator.cpp
=====
src\modules\physics\bullet\Bullet\LinearMath\btAlignedAllocator.cpp: In function 'void* btAlignedAllocDefault(size_t, int)':
src\modules\physics\bullet\Bullet\LinearMath\btAlignedAllocator.cpp:69:64: error: cast from 'char*' to 'long unsigned int' loses precision
src\modules\physics\bullet\Bullet\LinearMath\btAlignedAllocator.cpp: In function 'void* btAlignedAllocInternal(size_t, int)':
src\modules\physics\bullet\Bullet\LinearMath\btAlignedAllocator.cpp:172:64: error: cast from 'char*' to 'long unsigned int' loses precision
The code in question is this one here:

Code: Select all

static inline void *btAlignedAllocDefault(size_t size, int alignment)
{
  void *ret;
  char *real;
  unsigned long offset;

  real = (char *)sAllocFunc(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);
}
the "offset = " line and

Code: Select all

void*	btAlignedAllocInternal	(size_t size, int alignment)
{
	gNumAlignedAllocs++;
  void* ptr;
#if defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__)
	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);
	return ptr;
}
again the "offset = " line. "int" and "long" are 32-bit and "void*" is 64-bit. You might wanna fix this so it is not affected by compiler size variations. Best is to use "long long" as this is 64-bit as is "void*". Or better use char* as distance offset so you do not have to break over to integer.