Fix crash when importing large audio file
This commit is contained in:
@@ -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<int32>(minChunkSize, (int32)Math::AlignUp<uint32>(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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user