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

Godot Editor & Game crash in AudioServer if Bluetooth headphones added/removed #52275

Closed
tom-leys opened this issue Aug 31, 2021 · 4 comments
Closed

Comments

@tom-leys
Copy link

tom-leys commented Aug 31, 2021

Godot version

3.4.beta - head e443796 and 3.3.2.stable.official

System information

Windows 10

Issue description

Turning bluetooth headphones on or off when paired with PC crashes godot hard to console immediately 100%. Affects games, project menu and editors.

godot.windows.opt.tools.64.exe!CowData<Ref<AudioEffectInstance>>::get(int p_index) Line 156
	at \godot-src\core\cowdata.h(156)
[Inline Frame] godot.windows.opt.tools.64.exe!Vector<Ref<AudioEffectInstance>>::operator[](int) Line 87
	at \godot-src\core\vector.h(87)
godot.windows.opt.tools.64.exe!AudioServer::_mix_step() Line 366
	at \godot-src\servers\audio_server.cpp(366)
godot.windows.opt.tools.64.exe!AudioServer::_driver_process(int p_frames, int * p_buffer) Line 251
	at C:\gamedev\godot-src\servers\audio_server.cpp(251)

It appears to be a race condition where new bus->channels are made but without corresponding bus->channels->effect_instances.

void AudioServer::_mix_step() {
// ...

	for (int i = buses.size() - 1; i >= 0; i--) {
// ...

		//process effects
		if (!bus->bypass) {
			for (int j = 0; j < bus->effects.size(); j++) {
// ...

				for (int k = 0; k < bus->channels.size(); k++) {

// Crash occurs here, I imagine in bus->channels[k].effect_instances[j]
					if (!(bus->channels[k].active || bus->channels[k].effect_instances[j]->process_silence())) {
						continue;

Steps to reproduce

  1. Run Godot [editor or a game]
  2. Have a 5.1 sound system, bluetooth headphones. (not sure if the 5.1 is required)
  3. Set sound system as default if headphones are off. Otherwise headphones. (not sure if changing default is sufficient to reproduce)
  4. Ensure the audio stack has an effect (only reproduced with "Compressor" on master channel.
  5. Turn headphones on (if they were off) or off (if they were on). Either case reproduces 100%.
  6. Observe immediate Godot crash

Note:
I managed to reproduce just by changing the primary audio device between my headphones and speakers a few times. Took 3 switches.

Minimal reproduction project

A project where I accessed the audio menu, added a compressor and saved.
godot_Audio_compressor.zip

@Calinou Calinou added this to the 3.4 milestone Aug 31, 2021
@ellenhp
Copy link
Contributor

ellenhp commented Aug 31, 2021

Adding this one to the list. I just recently got a 5.1 system secondhand which will be helpful if this is related to the change in channel count.

@tom-leys
Copy link
Author

@ellenhp I realised that there is actually a bit more required for reproduction.

  1. It does not reproduce on the project list.
  2. It requires an audio effect in the sound stack (just a compressor is enough)
    image

I'm adding an example project to demonstrate.

@akien-mga akien-mga modified the milestones: 3.4, 3.5 Nov 8, 2021
@HeartoLazor
Copy link
Contributor

HeartoLazor commented Mar 30, 2022

We had the same issue in our game but with a ps5 dualsense controller crashing randomly editor/game after connecting it to a windows 10/11 pc by usb or bluetooth.
After debugging a bit We found the issue was the audio input from the ps5 controller and We found this issue.
We tested with the ps5 controller the demo attached in this issue and crashed.
Here is a video of what happens when the ps5 controller is connected in this issue demo using 3.4.4 with a debug custom build without modifications based in 3.4.4.stable for more console output:

Audioserver.crash.mp4

And here is an screenshot with some prints of channel/effect size and current index before crash:
image

@akien-mga
Copy link
Member

Fixed by #59778.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants