-
-
Notifications
You must be signed in to change notification settings - Fork 850
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
Components with overriden new operator. #1131
Comments
Have you tried it already in your project? Can you confirm that it works as expected? |
Yes! But if there are other places where EnTT is using a placement new, those may also need to be updated. Happy to work on a MWE without Jolt if you think that's useful. |
The only other class that uses placement new is |
Sure. As I said I was planning to provide a MWE without Jolt. So here it is: #include <entt/entt.hpp>
#include <stdlib.h>
#include <cstdlib>
namespace MyLib {
void* Allocate(size_t inSize)
{
return malloc(inSize);
}
void Free(void* inBlock)
{
free(inBlock);
}
void* AlignedAllocate(size_t inSize, size_t inAlignment)
{
#if defined(_WIN32)
return _aligned_malloc(inSize, inAlignment);
#else
void* block = nullptr;
posix_memalign(&block, inAlignment, inSize);
return block;
#endif
}
void AlignedFree(void* inBlock)
{
#if defined(_WIN32)
_aligned_free(inBlock);
#else
free(inBlock);
#endif
}
class Foo
{
public:
Foo(int x_)
: x(x_)
{}
public:
void* operator new(size_t inCount) { return MyLib::Allocate(inCount); }
void operator delete(void* inPointer) noexcept { MyLib::Free(inPointer); }
void* operator new[](size_t inCount) { return MyLib::Allocate(inCount); }
void operator delete[](void* inPointer) noexcept { MyLib::Free(inPointer); }
void* operator new(size_t inCount, std::align_val_t inAlignment)
{
return MyLib::AlignedAllocate(inCount, static_cast<size_t>(inAlignment));
}
void operator delete(void* inPointer, [[maybe_unused]] std::align_val_t inAlignment) noexcept
{
MyLib::AlignedFree(inPointer);
}
void* operator new[](size_t inCount, std::align_val_t inAlignment)
{
return MyLib::AlignedAllocate(inCount, static_cast<size_t>(inAlignment));
}
void operator delete[](void* inPointer, [[maybe_unused]] std::align_val_t inAlignment) noexcept
{
MyLib::AlignedFree(inPointer);
}
protected:
int x;
};
} // namespace MyLib
int main(void)
{
entt::registry r;
auto e = r.create();
r.emplace<MyLib::Foo>(e, 42); // <-- doesn't compile
return 0;
} |
You're right and I read it wrong. 😅 |
All good, thanks for looking into it! |
Hi. I'm trying to use EnTT with JoltPhysics. Jolt by default overrides its new/delete operators, which causes compilation issues with EnTT's usage of placement new operator here:
entt/src/entt/core/memory.hpp
Line 278 in fedcb92
As proposed in this discussion, the solution would be to replace
new(value)
with::new(value)
in EnTT's codebase.The text was updated successfully, but these errors were encountered: