FNA-XNA / FAudio

FAudio - Accuracy-focused XAudio reimplementation for open platforms
https://fna-xna.github.io/
Other
534 stars 72 forks source link

Fix deadlock in voice callbacks #342

Closed xtsm closed 1 month ago

xtsm commented 2 months ago

Second attempt. Previous here: https://github.com/FNA-XNA/FAudio/pull/337

Now that we release buffer lock before executing callbacks, some code from another thread can get scheduled between mutex unlock and callback call and observe empty buffer queue right before callback puts a new buffer there. XNA_Song determines the end of the song by simply checking if the queue is empty, which may lead to random playback breaks.

Not sure how to properly check for the song end but the buffer decoding function also zeroes out total samples counter when it finishes a EOS-flagged buffer so checking if that counter is zero should cut it... probably?

xtsm commented 2 months ago

@Romans-I-XVI could you please check if the problem you reported earlier (https://github.com/FNA-XNA/FAudio/pull/337#issuecomment-2049854555) persists in this branch?

Romans-I-XVI commented 2 months ago

@Romans-I-XVI could you please check if the problem you reported earlier (#337 (comment)) persists in this branch?

Just tested it out, this fixes the issue I was experiencing.

flibitijibibo commented 2 months ago

Sounds good - we're pretty close to the tag date so I'll merge this in right after 24.05 is out!

xtsm commented 1 month ago

@flibitijibibo no tag yet? i thought FNA 24.05 already got released

flibitijibibo commented 1 month ago

Fell behind due to SDL_GPU and some other things, will do a full review later today to be extra sure that this is solid.