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

Closing a window hangs for a second & causes pipewire to glitch #9948

Open
Azorlogh opened this issue Sep 28, 2023 · 4 comments
Open

Closing a window hangs for a second & causes pipewire to glitch #9948

Azorlogh opened this issue Sep 28, 2023 · 4 comments
Labels
A-Audio Sounds playback and modification A-Tasks Tools for parallel and async work C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@Azorlogh
Copy link
Contributor

Bevy version

Bevy v0.11.2

Relevant system information

Archlinux + pipewire 0.3.80 + x11

What you did

Close any bevy program's main window (if it includes the AudioPlugin).
Close any bevy program using Ctrl+C in the terminal (if it includes the AudioPlugin).

This happens whether or not bevy is actually playing any sound.

What went wrong

Expected: The window should close (almost) instantly without any audio issues.

Actual:
When I close the main window: it takes about ~1 second to close, and during that time, all of my desktop audio stutters (the last few milliseconds of audio repeat, causing audio popping).

When I Ctrl+C the terminal directly: the window closes almost instantly, and there is a short but loud popping sound.

It's not a major issue but it's a bit annoying as the audio glitching is often quite loud & uncomfortable, especially when it happens during a drum hit.

@Azorlogh Azorlogh added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Sep 28, 2023
@alice-i-cecile alice-i-cecile added O-Linux Specific to the Linux desktop operating system A-Audio Sounds playback and modification A-Tasks Tools for parallel and async work and removed S-Needs-Triage This issue needs to be labelled labels Sep 28, 2023
@A-Walrus
Copy link
Contributor

I can partially reproduce this.
On Ctrl+C everything sounds fine, but when closing the main window I get a bit of audio buzzing (a lot less than 1 second)

Fedora 38 + pipewire 0.3.80 + wayland

@SolarLiner SolarLiner added this to Audio Mar 12, 2024
@SolarLiner
Copy link
Contributor

It looks like it is because of this:

std::mem::forget(stream);

The audio stream then never gets cleaned up properly, which means that the audio thread gets unloaded but the audio driver is not notified and continues requesting audio data.

On some platforms the audio driver automatically zeroes-out the audio buffer, meaning that the output is silent when that happens, but on others the drivers don't bother because the audio data is supposed to be overwritten anyways.

A proper solution would be to not use std::mem::forget and store the OutputStream, as a non-send resource.

@SolarLiner SolarLiner added the S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! label Mar 12, 2024
@james7132
Copy link
Member

james7132 commented Mar 13, 2024

Oh man that's going to be difficult to resolve without impacting the efforts for #9122 where we're trying to remove NonSend from the World entirely, and using SendWrapper is not going to be sufficient if we cannot control which thread the World is dropped on.

@SolarLiner
Copy link
Contributor

SolarLiner commented Mar 13, 2024

@james7132 this is fixable though, by doing the same kind of wrapping that is done in kira for example, because it also has to wrap a cpal::Stream that is !Send + !Sync too.

@SolarLiner SolarLiner moved this to Open in Audio Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Audio Sounds playback and modification A-Tasks Tools for parallel and async work C-Bug An unexpected or incorrect behavior O-Linux Specific to the Linux desktop operating system S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
Status: Open
Development

No branches or pull requests

5 participants