BT_DECLARE_ALIGNED_ALLOCATOR new Operator Overload

Post Reply
Geometrian
Posts: 25
Joined: Sat Dec 03, 2011 8:37 pm
Contact:

BT_DECLARE_ALIGNED_ALLOCATOR new Operator Overload

Post by Geometrian »

Hi,

When trying to use Bullet with another library (which nowhere overloads new), I get many many errors. Some selected ones are below:

Code: Select all

//...
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\bullet-2.81-rev2613\src\linearmath\btvector3.h(82): error C2802: static member 'operator new' has no formal parameters
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\bullet-2.81-rev2613\src\linearmath\btvector3.h(82): error C2333: 'btVector3::operator new' : error in function declaration; skipping function body
//...
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\bullet-2.81-rev2613\src\linearmath\btvector3.h(82): error C2556: 'void *(__cdecl *btVector3::operator new(void))(size_t,void *)' : overloaded function differs only by return type from 'void *(__cdecl *btVector3::operator new(void))(size_t)'
1>          c:\program files (x86)\microsoft sdks\windows\v7.0a\bullet-2.81-rev2613\src\linearmath\btvector3.h(82) : see declaration of 'btVector3::operator new'
//...
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\bullet-2.81-rev2613\src\linearmath\btvector3.h(82): error C2556: 'btVector3 operator delete(void *,void *)' : overloaded function differs only by return type from 'void operator delete(void *,void *) throw()'
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(60) : see declaration of 'operator delete'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\bullet-2.81-rev2613\src\linearmath\btvector3.h(82): error C2371: 'operator delete' : redefinition; different basic types
1>          c:\program files (x86)\microsoft visual studio 10.0\vc\include\new(60) : see declaration of 'operator delete'
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\bullet-2.81-rev2613\src\linearmath\btvector3.h(82): error C2433: 'new' : '__forceinline' not permitted on data declarations
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\bullet-2.81-rev2613\src\linearmath\btvector3.h(82): error C2365: 'operator new' : redefinition; previous definition was 'function'
//...
How can this be fixed?
-G
Geometrian
Posts: 25
Joined: Sat Dec 03, 2011 8:37 pm
Contact:

Re: BT_DECLARE_ALIGNED_ALLOCATOR new Operator Overload

Post by Geometrian »

*Bump*

I don't know why this could be happening. The other library doesn't overload new as far as I know (although it certainly uses it).

The problem doesn't seem to occur if the library's header files are included after Bullet's and if no "new" allocations happen for Bullet objects in that compilation unit. The practical upshot is that the other library needs to be #include-d individually into each .cpp file that needs it, and the Bullet functionality completely separated.

Any ideas at all?
Geometrian
Posts: 25
Joined: Sat Dec 03, 2011 8:37 pm
Contact:

Re: BT_DECLARE_ALIGNED_ALLOCATOR new Operator Overload

Post by Geometrian »

Figured it out. The library indeed didn't overload "new", but it did #define it to something else, for purposes of catching memory leaks:

Code: Select all

#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#define new DEBUG_NEW
Is it possible to keep this definition, or something similar, but still use Bullet? Or, perhaps merely is there a way to let Bullet use its own new and the other library use its?
onne
Posts: 4
Joined: Mon Feb 10, 2014 12:25 pm

Re: BT_DECLARE_ALIGNED_ALLOCATOR new Operator Overload

Post by onne »

I would like to know the same thing... it seems that in some projects they have used a function for bullet specific stuff to prevent errors.

(https://github.com/blackberry/GamePlay)

Code: Select all

template T* bullet_new(const T& t1)
{
#ifdef GAMEPLAY_MEM_LEAK_DETECTION 
#undef new 
T* t = new T(t1);
#define new DEBUG_NEW
return t;
#else
return new T(t1);
#endif
}
micdoodle8
Posts: 3
Joined: Sat Mar 15, 2014 11:21 pm

Re: BT_DECLARE_ALIGNED_ALLOCATOR new Operator Overload

Post by micdoodle8 »

I'm also wondering the same thing. I'm unable to use custom new definitions with most bullet types.

Please pardon my bumping of an old topic, but no fix is currently available and redefining new for debugging purposes is quite common.
Post Reply