diff --git a/CHANGELOG.md b/CHANGELOG.md index 687ea48ed..76ce6a1ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ TombEngine releases are located in this repository (alongside with Tomb Editor): * Fixed flickering rat emitter. * Fixed player model submerging into the floor while swimming underwater. * Fixed custom shatter sounds with custom sound IDs not playing correctly. +* Fixed crashes with sound samples larger than 2 megabytes. ### New Features * Added multithreading and an option for it to flow system settings. diff --git a/TombEngine/Specific/level.cpp b/TombEngine/Specific/level.cpp index a48507e7f..a08041f27 100644 --- a/TombEngine/Specific/level.cpp +++ b/TombEngine/Specific/level.cpp @@ -1459,19 +1459,19 @@ void LoadSamples() TENLog("Sample count: " + std::to_string(sampleCount), LogLevel::Info); - int uncompressedSize = 0; - int compressedSize = 0; - char* buffer = (char*)malloc(2 * 1024 * 1024); + std::vector buffer; + buffer.reserve(2 * 1024 * 1024); for (int i = 0; i < sampleCount; i++) { - uncompressedSize = ReadInt32(); - compressedSize = ReadInt32(); - ReadBytes(buffer, compressedSize); - LoadSample(buffer, compressedSize, uncompressedSize, i); - } + int uncompressedSize = ReadInt32(); + int compressedSize = ReadInt32(); - free(buffer); + buffer.resize(compressedSize); + + ReadBytes(buffer.data(), compressedSize); + LoadSample(buffer.data(), compressedSize, uncompressedSize, i); + } } void LoadBoxes()