Commit 244ef260 authored by David Reid's avatar David Reid

Fix a bug where decoding would try to read 0 frames and throw an error.

parent 3ea17061
...@@ -47201,7 +47201,7 @@ MA_API ma_result ma_paged_audio_buffer_data_allocate_page(ma_paged_audio_buffer_ ...@@ -47201,7 +47201,7 @@ MA_API ma_result ma_paged_audio_buffer_data_allocate_page(ma_paged_audio_buffer_
return MA_OUT_OF_MEMORY; /* Too big. */ return MA_OUT_OF_MEMORY; /* Too big. */
} }
pPage = (ma_paged_audio_buffer_page*)ma_malloc((size_t)allocationSize, pAllocationCallbacks); /* Safe cast to size_t. */ pPage = (ma_paged_audio_buffer_page*)ma_malloc((size_t)allocationSize, pAllocationCallbacks); /* Safe cast to size_t. */
if (pPage == NULL) { if (pPage == NULL) {
return MA_OUT_OF_MEMORY; return MA_OUT_OF_MEMORY;
} }
...@@ -56556,15 +56556,19 @@ static ma_result ma_resource_manager_data_buffer_node_decode_next_page(ma_resour ...@@ -56556,15 +56556,19 @@ static ma_result ma_resource_manager_data_buffer_node_decode_next_page(ma_resour
framesToTryReading = framesRemaining; framesToTryReading = framesRemaining;
} }
pDst = ma_offset_ptr( if (framesToTryReading > 0) {
pDataBufferNode->data.decoded.pData, pDst = ma_offset_ptr(
pDataBufferNode->data.decoded.decodedFrameCount * ma_get_bytes_per_frame(pDataBufferNode->data.decoded.format, pDataBufferNode->data.decoded.channels) pDataBufferNode->data.decoded.pData,
); pDataBufferNode->data.decoded.decodedFrameCount * ma_get_bytes_per_frame(pDataBufferNode->data.decoded.format, pDataBufferNode->data.decoded.channels)
MA_ASSERT(pDst != NULL); );
MA_ASSERT(pDst != NULL);
result = ma_decoder_read_pcm_frames(pDecoder, pDst, framesToTryReading, &framesRead); result = ma_decoder_read_pcm_frames(pDecoder, pDst, framesToTryReading, &framesRead);
if (framesRead > 0) { if (framesRead > 0) {
pDataBufferNode->data.decoded.decodedFrameCount += framesRead; pDataBufferNode->data.decoded.decodedFrameCount += framesRead;
}
} else {
framesRead = 0;
} }
} break; } break;
...@@ -56932,10 +56936,10 @@ stage2: ...@@ -56932,10 +56936,10 @@ stage2:
/* The sound is still loading. We need to delay the freeing of the node to a safe time. */ /* The sound is still loading. We need to delay the freeing of the node to a safe time. */
ma_resource_manager_job job; ma_resource_manager_job job;
/* We need to mark the node as unavailable for the sake of the resource manager worker threads. */ /* We need to mark the node as unavailable for the sake of the resource manager worker threads. */
c89atomic_exchange_i32(&pDataBufferNode->result, MA_UNAVAILABLE); c89atomic_exchange_i32(&pDataBufferNode->result, MA_UNAVAILABLE);
job = ma_resource_manager_job_init(MA_RESOURCE_MANAGER_JOB_FREE_DATA_BUFFER_NODE); job = ma_resource_manager_job_init(MA_RESOURCE_MANAGER_JOB_FREE_DATA_BUFFER_NODE);
job.order = ma_resource_manager_data_buffer_node_next_execution_order(pDataBufferNode); job.order = ma_resource_manager_data_buffer_node_next_execution_order(pDataBufferNode);
job.freeDataBufferNode.pDataBufferNode = pDataBufferNode; job.freeDataBufferNode.pDataBufferNode = pDataBufferNode;
...@@ -57126,11 +57130,11 @@ static ma_result ma_resource_manager_data_buffer_init_internal(ma_resource_manag ...@@ -57126,11 +57130,11 @@ static ma_result ma_resource_manager_data_buffer_init_internal(ma_resource_manag
/* NOTE: Do not release the init fence here. It will have been done by the job. */ /* NOTE: Do not release the init fence here. It will have been done by the job. */
/* Make sure we return an error if initialization failed on the async thread. */ /* Make sure we return an error if initialization failed on the async thread. */
result = ma_resource_manager_data_buffer_result(pDataBuffer); result = ma_resource_manager_data_buffer_result(pDataBuffer);
if (result == MA_BUSY) { if (result == MA_BUSY) {
result = MA_SUCCESS; result = MA_SUCCESS;
} }
} }
} }
...@@ -58767,7 +58771,7 @@ static ma_result ma_resource_manager_process_job__page_data_buffer_node(ma_resou ...@@ -58767,7 +58771,7 @@ static ma_result ma_resource_manager_process_job__page_data_buffer_node(ma_resou
/* Don't do any more decoding if the data buffer has started the uninitialization process. */ /* Don't do any more decoding if the data buffer has started the uninitialization process. */
if (ma_resource_manager_data_buffer_node_result(pJob->pageDataBufferNode.pDataBufferNode) != MA_BUSY) { if (ma_resource_manager_data_buffer_node_result(pJob->pageDataBufferNode.pDataBufferNode) != MA_BUSY) {
result = ma_resource_manager_data_buffer_node_result(pJob->pageDataBufferNode.pDataBufferNode); result = ma_resource_manager_data_buffer_node_result(pJob->pageDataBufferNode.pDataBufferNode);
goto done; goto done;
} }
if (pJob->order != pJob->pageDataBufferNode.pDataBufferNode->executionPointer) { if (pJob->order != pJob->pageDataBufferNode.pDataBufferNode->executionPointer) {
...@@ -58885,18 +58889,18 @@ done: ...@@ -58885,18 +58889,18 @@ done:
ma_fence_release(pJob->loadDataBuffer.pDoneFence); ma_fence_release(pJob->loadDataBuffer.pDoneFence);
} }
/* /*
If at this point the data buffer has not had it's connector initialized, it means the If at this point the data buffer has not had it's connector initialized, it means the
notification event was never signalled which means we need to signal it here. notification event was never signalled which means we need to signal it here.
*/ */
if (pJob->loadDataBuffer.pDataBuffer->isConnectorInitialized == MA_FALSE && result != MA_SUCCESS) { if (pJob->loadDataBuffer.pDataBuffer->isConnectorInitialized == MA_FALSE && result != MA_SUCCESS) {
if (pJob->loadDataBuffer.pInitNotification != NULL) { if (pJob->loadDataBuffer.pInitNotification != NULL) {
ma_async_notification_signal(pJob->loadDataBuffer.pInitNotification); ma_async_notification_signal(pJob->loadDataBuffer.pInitNotification);
} }
if (pJob->loadDataBuffer.pInitFence != NULL) { if (pJob->loadDataBuffer.pInitFence != NULL) {
ma_fence_release(pJob->loadDataBuffer.pInitFence); ma_fence_release(pJob->loadDataBuffer.pInitFence);
} }
} }
c89atomic_fetch_add_32(&pJob->loadDataBuffer.pDataBuffer->executionPointer, 1); c89atomic_fetch_add_32(&pJob->loadDataBuffer.pDataBuffer->executionPointer, 1);
return result; return result;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment