Skip to content

Commit

Permalink
fix: fix use_mimalloc crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Dofes committed Dec 29, 2024
1 parent 490f105 commit 2d07e16
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/ll/core/tweak/ModifyMemoryAllocator.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "ll/api/memory/Hook.h"

#include "mc/deps/core/memory/IMemoryAllocator.h"
#include "mc/deps/core/memory/Memory.h"
#include "mc/deps/core/memory/InternalHeapAllocator.h"

namespace ll::memory {
auto replaceMemoryAllocator = []() -> bool {
auto allocator = *reinterpret_cast<void***>(&getDefaultAllocator());
auto vftable = ::Bedrock::Memory::InternalHeapAllocator::$vftable();

LL_AUTO_STATIC_HOOK(ReplaceMemoryAllocator, HookPriority::High, ::Bedrock::Memory::getDefaultAllocator, ::Bedrock::Memory::IMemoryAllocator&) {
return ::ll::memory::getDefaultAllocator();
}
modify(vftable, 8 * sizeof(void*), [&] {
for (size_t i = 0; i < 8; ++i) {
vftable[i] = allocator[i];
}
});

} // namespace ll::memory
return true;
}();
} // namespace ll::memory

0 comments on commit 2d07e16

Please sign in to comment.