Skip to content

sdl_sound.cpp: Correct default device selection logic. #13914

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vanfanel
Copy link
Contributor

@vanfanel vanfanel commented Jul 5, 2025

The logic on the SDL_OpenAudioDevice() call was inverted.
This:
SDL_OpenAudioDevice(dev.m_def ? nullptr : dev.m_name.c_str(), 0, &dspec, &ospec, 0);
...would mean that if dev.m_def has non-zero value, nullptr would be used instead of dev.m_name.c_str(), which makes no sense: we want to use dev.m_name.c_str() when dev.m_def is non-zero, and nullptr otherwise.

As a side-effect, this works around SDL2's ALSA backend inability to report a default audio device with SDL_GetDefaultAudioInfo() and thus is a workaround for issue #13910
That 's because, when no default device is reported by SDL_GetDefaultAudioInfo(), nullptr is properly passed to SDL_OpenAudioDevice() now and the default device is chosen by SDL2 as most SDL2 programs/games do.

@ajrhacker
Copy link
Contributor

I strongly suspect this fix is technically incorrect and just masks the problem. It forces SDL to select the default device for any device not found through SDL_GetDefaultAudioInfo.

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

Successfully merging this pull request may close these issues.

2 participants