From 07ae0be2ad2c277ae55d9a2fdf2b1e1469d75068 Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 25 Aug 2020 18:05:08 +1000 Subject: [PATCH] Resource Manager: Fix a bug when reusing an already-loaded data buffer. --- research/ma_engine.c | 13 ++++++++++++- research/ma_engine.h | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/research/ma_engine.c b/research/ma_engine.c index 27b36205..dfacbe2a 100644 --- a/research/ma_engine.c +++ b/research/ma_engine.c @@ -30,6 +30,7 @@ int main(int argc, char** argv) ma_result result; ma_engine engine; ma_sound sound; + ma_sound sound2; sound_loaded_notification loadNotification; @@ -49,7 +50,14 @@ int main(int argc, char** argv) loadNotification.cb.onSignal = on_sound_loaded; loadNotification.pSound = &sound; - result = ma_sound_init_from_file(&engine, argv[1], MA_DATA_SOURCE_FLAG_DECODE | MA_DATA_SOURCE_FLAG_ASYNC | MA_DATA_SOURCE_FLAG_STREAM, &loadNotification, NULL, &sound); + result = ma_sound_init_from_file(&engine, argv[1], MA_DATA_SOURCE_FLAG_DECODE /*| MA_DATA_SOURCE_FLAG_ASYNC | MA_DATA_SOURCE_FLAG_STREAM*/, &loadNotification, NULL, &sound); + if (result != MA_SUCCESS) { + printf("Failed to load sound: %s\n", argv[1]); + ma_engine_uninit(&engine); + return -1; + } + + result = ma_sound_init_from_file(&engine, argv[1], MA_DATA_SOURCE_FLAG_DECODE /*| MA_DATA_SOURCE_FLAG_ASYNC | MA_DATA_SOURCE_FLAG_STREAM*/, &loadNotification, NULL, &sound2); if (result != MA_SUCCESS) { printf("Failed to load sound: %s\n", argv[1]); ma_engine_uninit(&engine); @@ -74,6 +82,9 @@ int main(int argc, char** argv) ma_sound_set_stop_delay(&sound, 1000); ma_sound_start(&sound); + ma_sleep(1000); + ma_sound_start(&sound2); + //ma_sleep(2000); printf("Stopping...\n"); //ma_sound_stop(&sound); diff --git a/research/ma_engine.h b/research/ma_engine.h index d2e54948..dbde8c5c 100644 --- a/research/ma_engine.h +++ b/research/ma_engine.h @@ -2197,6 +2197,12 @@ static ma_result ma_resource_manager_data_buffer_init_nolock(ma_resource_manager return result; /* Should never happen. Failed to increment the reference count. */ } + result = ma_resource_manager_data_buffer_init_connector(pDataBuffer); + if (result != MA_SUCCESS) { + ma_resource_manager_data_buffer_node_free(pDataBuffer->pResourceManager, pDataBuffer->pNode); + return result; + } + if (pNotification != NULL) { ma_async_notification_signal(pNotification); }