From 562637f5993f4bea2b883919fbd42fde497cc8ec Mon Sep 17 00:00:00 2001 From: Lwmte <3331699+Lwmte@users.noreply.github.com> Date: Fri, 14 Feb 2025 23:10:40 +0100 Subject: [PATCH] Fixed #1574 --- CHANGELOG.md | 1 + TombEngine/Specific/level.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) 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()