Add engine fatal error types handling

Add general out-of-memory handling
Add safety memory buffer for crash or out of memory handling
Refactor Globals exit/error state to be in Engine class
This commit is contained in:
Wojtek Figat
2025-01-24 20:07:12 +01:00
parent fa2f2e3104
commit cf40facefe
20 changed files with 166 additions and 159 deletions

View File

@@ -14,18 +14,7 @@ MemoryWriteStream::MemoryWriteStream()
MemoryWriteStream::MemoryWriteStream(uint32 capacity)
: _capacity(capacity)
{
if (capacity > 0)
{
_buffer = (byte*)Allocator::Allocate(capacity);
if (_buffer == nullptr)
{
OUT_OF_MEMORY;
}
}
else
{
_buffer = nullptr;
}
_buffer = capacity > 0 ? (byte*)Allocator::Allocate(capacity) : nullptr;
_position = _buffer;
}
@@ -46,10 +35,6 @@ void* MemoryWriteStream::Move(uint32 bytes)
while (newCapacity < position + bytes)
newCapacity *= 2;
byte* newBuf = (byte*)Allocator::Allocate(newCapacity);
if (newBuf == nullptr)
{
OUT_OF_MEMORY;
}
Platform::MemoryCopy(newBuf, _buffer, _capacity);
Allocator::Free(_buffer);
@@ -73,10 +58,6 @@ void MemoryWriteStream::Reset(uint32 capacity)
{
Allocator::Free(_buffer);
_buffer = (byte*)Allocator::Allocate(capacity);
if (_buffer == nullptr)
{
OUT_OF_MEMORY;
}
_capacity = capacity;
}
@@ -142,10 +123,6 @@ void MemoryWriteStream::WriteBytes(const void* data, uint32 bytes)
while (newCapacity < position + bytes)
newCapacity *= 2;
byte* newBuf = (byte*)Allocator::Allocate(newCapacity);
if (newBuf == nullptr)
{
OUT_OF_MEMORY;
}
Platform::MemoryCopy(newBuf, _buffer, _capacity);
Allocator::Free(_buffer);