1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-19 21:13:05 +01:00

implement saving of objects and fix other bugs

This commit is contained in:
Ted John
2016-06-26 23:57:24 +01:00
parent 01cd37316c
commit 09782e980c
5 changed files with 97 additions and 29 deletions

View File

@@ -55,20 +55,37 @@ namespace ObjectFactory
{
size_t bufferSize = 0x600000;
void * buffer = Memory::Allocate<void>(bufferSize);
bufferSize = sawyercoding_read_chunk_with_size(file, (uint8 *)buffer, bufferSize);
buffer = Memory::Reallocate(buffer, bufferSize);
auto ms = MemoryStream(buffer, bufferSize);
try
if (buffer == nullptr)
{
result->ReadLegacy(&ms);
}
catch (Exception ex)
{
Console::Error::WriteFormat("Error reading object: '%s'", path);
Console::Error::WriteLine();
log_error("Unable to allocate data buffer.");
delete result;
result = nullptr;
}
else
{
try
{
bufferSize = sawyercoding_read_chunk_with_size(file, (uint8 *)buffer, bufferSize);
if (bufferSize == SIZE_MAX)
{
throw IOException("Error decoding data.");
}
buffer = Memory::Reallocate(buffer, bufferSize);
auto ms = MemoryStream(buffer, bufferSize);
result->ReadLegacy(&ms);
Memory::Free(buffer);
}
catch (Exception ex)
{
Memory::Free(buffer);
Console::Error::WriteFormat("Error reading object: '%s'", path);
Console::Error::WriteLine();
delete result;
result = nullptr;
}
}
}
}
SDL_RWclose(file);