Fix data race UB (audio thread pushing to its own message queue) triggered by WAV export #272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In a previous PR #137, I replaced audio thread communication with inter-thread message queues to prevent blocking the audio thread and interrupting playback. Unfortunately I missed a case where when you perform WAV export, the audio thread itself is pushing into the message queue intended for GUI-to-audio commands. This results in a UB data race on the lock-free ring buffer queue, which could result in missing or invalid commands being processed.
Separately I've noticed crashes upon WAV export where
m_bRendering
is true, butm_pWaveFile
is null while callingm_pWaveFile->WriteWave()
. I don't know how it happens, but it may be related to the above UB.I'm fixing the data race by introducing a separate object for messages sent from the audio thread to itself. Hopefully it fixes the WAV export crash, but it's intermittent and I can't reproduce it on demand on the old code, nor prove that this change fixes it.
Changes in this PR: