From 687e9e55028d99a60c3e2606c81a4b04a1462b8b Mon Sep 17 00:00:00 2001 From: David Reid Date: Thu, 14 Jan 2021 17:23:48 +1000 Subject: [PATCH] Fix a bug in the node graph relating to attaching and detaching nodes. This was setting the previous pointer of newly attached nodes to NULL instead of a pointer to the dummy head node. This then results in the dummy head node never being updated when the node is detached which in turn results in an uninitialized node being dereferenced. --- research/miniaudio_engine.c | 9 ++++++--- research/miniaudio_engine.h | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/research/miniaudio_engine.c b/research/miniaudio_engine.c index 9422838f..a296bc3e 100644 --- a/research/miniaudio_engine.c +++ b/research/miniaudio_engine.c @@ -78,7 +78,7 @@ 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); @@ -93,6 +93,8 @@ int main(int argc, char** argv) } #endif + + /*ma_data_source_seek_to_pcm_frame(sound.pDataSource, 5000000);*/ //ma_sound_group_set_pan(ma_engine_get_master_sound_group(&engine), -1); @@ -105,7 +107,7 @@ int main(int argc, char** argv) /*ma_sound_set_volume(&sound, 0.25f);*/ /*ma_sound_set_pitch(&sound, 1.2f);*/ /*ma_sound_set_pan(&sound, 0.0f);*/ - //ma_sound_set_looping(&sound, MA_TRUE); + ma_sound_set_looping(&sound, MA_TRUE); //ma_sound_seek_to_pcm_frame(&sound, 6000000); //ma_sound_set_start_time(&sound, 1110); //ma_sound_set_volume(&sound, 0.5f); @@ -116,6 +118,7 @@ int main(int argc, char** argv) //ma_sound_set_volume(&sound, 1); //ma_sound_set_start_time(&sound, 48000); ma_sound_start(&sound); + /*ma_sound_uninit(&sound);*/ //ma_sleep(1000); //ma_sound_set_looping(&sound2, MA_TRUE); @@ -134,7 +137,7 @@ int main(int argc, char** argv) ma_engine_play_sound(&engine, argv[3], NULL);*/ #endif -#if 1 +#if 0 float pitch = 1; float pitchStep = 0.01f; float pitchMin = 0.125f; diff --git a/research/miniaudio_engine.h b/research/miniaudio_engine.h index 7aabcad8..b7545741 100644 --- a/research/miniaudio_engine.h +++ b/research/miniaudio_engine.h @@ -2493,7 +2493,7 @@ static void ma_node_input_bus_attach(ma_node_input_bus* pInputBus, ma_node_outpu */ ma_node_input_bus_lock(pInputBus); { - ma_node_output_bus* pNewPrev = NULL; + ma_node_output_bus* pNewPrev = &pInputBus->head; ma_node_output_bus* pNewNext = (ma_node_output_bus*)c89atomic_load_ptr(&pInputBus->head.pNext); /* Update the local output bus. */ @@ -8714,6 +8714,10 @@ MA_API ma_result ma_engine_init(const ma_engine_config* pConfig, ma_engine* pEng ma_engine_config engineConfig; ma_context_config contextConfig; + if (pEngine != NULL) { + MA_ZERO_OBJECT(pEngine); + } + /* The config is allowed to be NULL in which case we use defaults for everything. */ if (pConfig != NULL) { engineConfig = *pConfig;