mackron / miniaudio

Audio playback and capture library written in C, in a single source file.
https://miniaud.io
Other
4.07k stars 361 forks source link

Fix bug in ma_node_detach_full(...) #782

Closed xielock closed 11 months ago

xielock commented 11 months ago

In function ma_node_detach_full(...), when we want to detach InputBus of one node, we iterate pInputBus->head. However, when we call ma_node_detach_output_bus(...) ->ma_node_input_bus_detach__no_output_bus_lock(...) in this funciton, we set &pOutputBus->pNext be NULL, which means we never step into the second iteration and we can't detach all pInputBus of the node. Because ma_node_input_bus_detach__no_output_bus_lock(...) already set the &pOldPrev's pNext be pOldNext, so I think when we iterate InputBus can use pInputBus->head.pNext instead.

mackron commented 11 months ago

Good catch. Thanks. Anything related to attaching and detaching in the node graph get's finicky and needs to be handled with care, but I think your explanation and code change seems logical. Fortunately the section of code your change is referencing does not have any particularly annoying lock-free thread-safety issues because the node's outputs are detached from the graph at an earlier stage so I can't see an immediate reason not to get this merged. I will give this a test as soon as I get a chance and report back.

xielock commented 11 months ago

Thank you for your positive feedback and for considering merging my code change. I'll patiently await the results of your testing.

mackron commented 11 months ago

This seems to work fine in my testing. I've gone ahead and merged that into the dev branch.