CMemory falls back to malloc if uninitialized

This commit is contained in:
Jack Andersen 2015-12-02 12:05:44 -10:00
parent 04fa61e0c2
commit 3fbbff133c
2 changed files with 19 additions and 1 deletions

View File

@ -73,6 +73,8 @@ IAllocator& CMemorySys::GetGameAllocator() {return g_gameAllocator;}
void* operator new(std::size_t sz) void* operator new(std::size_t sz)
{ {
if (!Retro::g_memoryAllocatorReady)
return malloc(sz);
Retro::CCallStack cs("?\?(?\?)", "UnknownType"); Retro::CCallStack cs("?\?(?\?)", "UnknownType");
return Retro::CMemory::Alloc(sz, return Retro::CMemory::Alloc(sz,
Retro::IAllocator::EHint::None, Retro::IAllocator::EHint::None,
@ -84,6 +86,8 @@ void* operator new(std::size_t sz)
void* operator new(std::size_t sz, void* operator new(std::size_t sz,
const char* funcName, const char* typeName) const char* funcName, const char* typeName)
{ {
if (!Retro::g_memoryAllocatorReady)
return malloc(sz);
Retro::CCallStack cs(funcName, typeName); Retro::CCallStack cs(funcName, typeName);
return Retro::CMemory::Alloc(sz, return Retro::CMemory::Alloc(sz,
Retro::IAllocator::EHint::None, Retro::IAllocator::EHint::None,
@ -94,11 +98,18 @@ void* operator new(std::size_t sz,
void operator delete(void* ptr) noexcept void operator delete(void* ptr) noexcept
{ {
if (!Retro::g_memoryAllocatorReady)
{
free(ptr);
return;
}
Retro::CMemory::Free(ptr); Retro::CMemory::Free(ptr);
} }
void* operator new[](std::size_t sz) void* operator new[](std::size_t sz)
{ {
if (!Retro::g_memoryAllocatorReady)
return malloc(sz);
Retro::CCallStack cs("?\?(?\?)", "UnknownType"); Retro::CCallStack cs("?\?(?\?)", "UnknownType");
return Retro::CMemory::Alloc(sz, return Retro::CMemory::Alloc(sz,
Retro::IAllocator::EHint::None, Retro::IAllocator::EHint::None,
@ -110,6 +121,8 @@ void* operator new[](std::size_t sz)
void* operator new[](std::size_t sz, void* operator new[](std::size_t sz,
const char* funcName, const char* typeName) const char* funcName, const char* typeName)
{ {
if (!Retro::g_memoryAllocatorReady)
return malloc(sz);
Retro::CCallStack cs(funcName, typeName); Retro::CCallStack cs(funcName, typeName);
return Retro::CMemory::Alloc(sz, return Retro::CMemory::Alloc(sz,
Retro::IAllocator::EHint::None, Retro::IAllocator::EHint::None,
@ -120,5 +133,10 @@ void* operator new[](std::size_t sz,
void operator delete[](void* ptr) noexcept void operator delete[](void* ptr) noexcept
{ {
if (!Retro::g_memoryAllocatorReady)
{
free(ptr);
return;
}
Retro::CMemory::Free(ptr); Retro::CMemory::Free(ptr);
} }

2
hecl

@ -1 +1 @@
Subproject commit e98d0f25d94acca5675f96fe03cbb536d126faec Subproject commit 1cb02347a52ba2d785d05c12bedbdcee3030ecbb