diff options
| author | Dan Engelbrecht <[email protected]> | 2023-05-23 10:47:28 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-23 10:47:28 +0200 |
| commit | 45aad3d98ee23e7f0e5873962a55c15a53d6b5c7 (patch) | |
| tree | 8fbf9907a934c69aeea3e2fdf16802ae4b8c9ad0 /src/zencore/iobuffer.cpp | |
| parent | streaming decompression support (#142) (diff) | |
| download | zen-45aad3d98ee23e7f0e5873962a55c15a53d6b5c7.tar.xz zen-45aad3d98ee23e7f0e5873962a55c15a53d6b5c7.zip | |
use exception when allocations fail rather than asserts (#319)
* use exception when allocations fail rather than asserts
* changelog
Diffstat (limited to 'src/zencore/iobuffer.cpp')
| -rw-r--r-- | src/zencore/iobuffer.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/zencore/iobuffer.cpp b/src/zencore/iobuffer.cpp index f0eba80ed..f53d80778 100644 --- a/src/zencore/iobuffer.cpp +++ b/src/zencore/iobuffer.cpp @@ -40,8 +40,12 @@ IoBufferCore::AllocateBuffer(size_t InSize, size_t Alignment) const if (((InSize & 0xffFF) == 0) && (Alignment == 0x10000)) { m_Flags.fetch_or(kLowLevelAlloc, std::memory_order_relaxed); - m_DataPtr = VirtualAlloc(nullptr, InSize, MEM_COMMIT, PAGE_READWRITE); - + void* Ptr = VirtualAlloc(nullptr, InSize, MEM_COMMIT, PAGE_READWRITE); + if (!Ptr) + { + ThrowLastError(fmt::format("VirtualAlloc failed for {:#x} bytes aligned to {:#x}", InSize, Alignment)); + } + m_DataPtr = Ptr; return; } #endif // ZEN_PLATFORM_WINDOWS @@ -53,8 +57,10 @@ IoBufferCore::AllocateBuffer(size_t InSize, size_t Alignment) const void* Ptr = Memory::Alloc(InSize, Alignment); #endif - ZEN_ASSERT(Ptr); - + if (!Ptr) + { + ThrowOutOfMemory(fmt::format("failed allocating {:#x} bytes aligned to {:#x}", InSize, Alignment)); + } m_DataPtr = Ptr; } |