Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always call start() on audio stream before mixing #46202

Merged
merged 2 commits into from
Feb 19, 2021

Conversation

ellenhp
Copy link
Contributor

@ellenhp ellenhp commented Feb 19, 2021

Fixes #28110

This is the AudioStreamPlayer counterpart of #46151. This bug seems to only crop up when people pause in a scene's _ready() or immediately after playing an AudioStreamPlayer.

The problematic codepath seems to be:

  1. play() being called and setting active = true (can be done in script or through autoplay+entering the tree)
  2. pausing the node, which causes set_stream_paused(true) to be called
  3. _mix_audio() being called which triggers the fadeout code, leading to a mix() call on an AudioStreamPlaybackResampled (like for an ogg or mp3), which doesn't have a check that start() has first been called.

This triggers unintialized memory being copied into the audio buffer. If any of the values in that block of memory are NaN, they get propagated through into whatever audio effect chain the project has. At least for a reverb effect, that NaNs out the entire audio stream coming out of that bus.

This PR also adds a false-initialization to use_fadeout since before it would just be uninitialized garbage.

HUGE thank you to @jjmontesl for the help testing this one, and on your insights in the comments on the bug!

Testing can be done with this project which is specifically configured to repro the bug.

mix_before_start.zip

As always with these audio bugs, please watch your volume while reproducing the bug, especially if you wear headphones or have good speakers.

@ellenhp ellenhp marked this pull request as ready for review February 19, 2021 04:46
@ellenhp ellenhp requested a review from a team as a code owner February 19, 2021 04:46
@akien-mga akien-mga added bug cherrypick:3.x Considered for cherry-picking into a future 3.x release topic:audio labels Feb 19, 2021
@akien-mga akien-mga added this to the 4.0 milestone Feb 19, 2021
@akien-mga akien-mga merged commit c8c3bcd into godotengine:master Feb 19, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.2.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Feb 19, 2021
@ellenhp ellenhp deleted the fix_mix_before_start branch February 20, 2021 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Audio stops working after scene reload.
3 participants