From cab0f92da82bc631bc79230a21a8d2dffe4ced85 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 11 Mar 2025 17:01:33 +0100 Subject: [PATCH] Fix crash when importing large audio file --- Source/Engine/ContentImporters/ImportAudio.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Engine/ContentImporters/ImportAudio.cpp b/Source/Engine/ContentImporters/ImportAudio.cpp index 00b914259..1cb6143be 100644 --- a/Source/Engine/ContentImporters/ImportAudio.cpp +++ b/Source/Engine/ContentImporters/ImportAudio.cpp @@ -159,19 +159,19 @@ CreateAssetResult ImportAudio::Import(CreateAssetContext& context, AudioDecoder& else { // Split audio data into a several chunks (uniform data spread) - const int32 minChunkSize = 1 * 1024 * 1024; // 1 MB - const int32 dataAlignment = info.NumChannels * bytesPerSample; // Ensure to never split samples in-between (eg. 24-bit that uses 3 bytes) - const int32 chunkSize = Math::Max(minChunkSize, (int32)Math::AlignUp(bufferSize / ASSET_FILE_DATA_CHUNKS, dataAlignment)); - const int32 chunksCount = Math::CeilToInt((float)bufferSize / chunkSize); + const uint32 minChunkSize = 1 * 1024 * 1024; // 1 MB + const uint32 dataAlignment = info.NumChannels * bytesPerSample * ASSET_FILE_DATA_CHUNKS; // Ensure to never split samples in-between (eg. 24-bit that uses 3 bytes) + const uint32 chunkSize = Math::AlignUp(Math::Max(minChunkSize, bufferSize / ASSET_FILE_DATA_CHUNKS), dataAlignment); + const int32 chunksCount = Math::CeilToInt((float)bufferSize / (float)chunkSize); ASSERT(chunksCount > 0 && chunksCount <= ASSET_FILE_DATA_CHUNKS); byte* ptr = sampleBuffer.Get(); - int32 size = bufferSize; + uint32 size = bufferSize; for (int32 chunkIndex = 0; chunkIndex < chunksCount; chunkIndex++) { if (context.AllocateChunk(chunkIndex)) return CreateAssetResult::CannotAllocateChunk; - const int32 t = Math::Min(size, chunkSize); + const uint32 t = Math::Min(size, chunkSize); WRITE_DATA(chunkIndex, ptr, t);