Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placement new with Jolt allocators #1009

Closed
jdumas opened this issue Mar 26, 2024 · 2 comments
Closed

Placement new with Jolt allocators #1009

jdumas opened this issue Mar 26, 2024 · 2 comments

Comments

@jdumas
Copy link

jdumas commented Mar 26, 2024

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.

@jrouwe
Copy link
Owner

jrouwe commented Mar 26, 2024

See: #986

@jrouwe jrouwe closed this as completed Mar 26, 2024
@jdumas
Copy link
Author

jdumas commented Mar 26, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants