Placement new with Jolt allocators
Closed this issue · 2 comments
jdumas commented
Hi,
I'm having some trouble using Jolt's overidden new/delete operators with a placement new syntax. Here is an example code:
using T = JPH::BodyID;
T source;
T target;
new(&target) T(source);
Which compiles with the following error (Xcode15.3 on macOS, using Jolt 4.0.2):
/Users/jedumas/external/git/JoltPhysicsHelloWorld/Source/HelloWorld.cpp:366:2: error: no matching function for call to 'operator new'
new(&target) T(source);
^ ~~~~~~~~~
/Users/jedumas/external/git/JoltPhysicsHelloWorld/Build/build/_deps/joltphysics-src/Build/../Jolt/Physics/Body/BodyID.h:15:2: note: candidate function not viable: no known conversion from 'T *' (aka 'JPH::BodyID *') to 'std::align_val_t' for 2nd argument
JPH_OVERRIDE_NEW_DELETE
^
/Users/jedumas/external/git/JoltPhysicsHelloWorld/Build/build/_deps/joltphysics-src/Build/../Jolt/Core/Memory.h:34:19: note: expanded from macro 'JPH_OVERRIDE_NEW_DELETE'
JPH_INLINE void *operator new (size_t inCount, std::align_val_t inAlignment) { return JPH::AlignedAllocate(inCount, static_cast<size_t>(inAlignment)); } \
^
/Users/jedumas/external/git/JoltPhysicsHelloWorld/Build/build/_deps/joltphysics-src/Build/../Jolt/Physics/Body/BodyID.h:15:2: note: candidate function not viable: requires single argument 'inCount', but 2 arguments were provided
/Users/jedumas/external/git/JoltPhysicsHelloWorld/Build/build/_deps/joltphysics-src/Build/../Jolt/Core/Memory.h:30:19: note: expanded from macro 'JPH_OVERRIDE_NEW_DELETE'
JPH_INLINE void *operator new (size_t inCount) { return JPH::Allocate(inCount); } \
^
1 error generated.
When compiling with JPH_DISABLE_CUSTOM_ALLOCATOR
defined the error goes away.
jdumas commented
Thanks!