From c3e2038c3add6cd2ab1092775caca35d1f7b750d Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 14 Jun 2020 12:54:14 +1000 Subject: [PATCH] Fix a crash trying to seek on a failed async data stream. --- research/ma_engine.c | 8 ++++---- research/ma_engine.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/research/ma_engine.c b/research/ma_engine.c index d6a7cca4..b1cf4697 100644 --- a/research/ma_engine.c +++ b/research/ma_engine.c @@ -34,13 +34,13 @@ int main(int argc, char** argv) #if 1 - result = ma_engine_sound_init_from_file(&engine, argv[1], MA_DATA_SOURCE_FLAG_DECODE | MA_DATA_SOURCE_FLAG_ASYNC | MA_DATA_SOURCE_FLAG_STREAM, NULL, &sound); + result = ma_engine_sound_init_from_file(&engine, /*argv[1]*/ "unknownfile.wav", MA_DATA_SOURCE_FLAG_DECODE | MA_DATA_SOURCE_FLAG_ASYNC | MA_DATA_SOURCE_FLAG_STREAM, NULL, &sound); if (result != MA_SUCCESS) { ma_engine_uninit(&engine); return -1; } - /*ma_data_source_seek_to_pcm_frame(sound.pDataSource, 5000000);*/ + ma_data_source_seek_to_pcm_frame(sound.pDataSource, 5000000); ma_engine_sound_set_volume(&engine, &sound, 0.25f); ma_engine_sound_set_pitch(&engine, &sound, 1.0f); @@ -51,8 +51,8 @@ int main(int argc, char** argv) #if 1 /*ma_engine_play_sound(&engine, argv[1], NULL);*/ - ma_engine_play_sound(&engine, argv[2], NULL); - ma_engine_play_sound(&engine, argv[3], NULL); + /*ma_engine_play_sound(&engine, argv[2], NULL); + ma_engine_play_sound(&engine, argv[3], NULL);*/ #endif #if 0 diff --git a/research/ma_engine.h b/research/ma_engine.h index a188ec67..42c5c62a 100644 --- a/research/ma_engine.h +++ b/research/ma_engine.h @@ -3143,6 +3143,11 @@ static ma_result ma_resource_manager_handle_message__seek_data_stream(ma_resourc MA_ASSERT(pResourceManager != NULL); MA_ASSERT(pDataStream != NULL); + /* For streams the status should be MA_SUCCESS for this to do anything. */ + if (pDataStream->result != MA_SUCCESS || pDataStream->isDecoderInitialized == MA_FALSE) { + return MA_INVALID_OPERATION; + } + /* With seeking we just assume both pages are invalid and the relative frame cursor at at position 0. This is basically exactly the same as loading, except instead of initializing the decoder, we seek to a frame.