Fix data race UB (audio thread pushing to its own message queue) triggered by WAV export#272
Merged
nyanpasu64 merged 1 commit intomainfrom May 5, 2024
Merged
Conversation
Hopefully fixes random crash upon WAV export.
Collaborator
|
looks good to me |
Collaborator
Author
|
the crash still happens.
|
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_bRenderingis true, butm_pWaveFileis 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: