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

openal_track: Improve failure handling #3974

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/sound/openal_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ bool sound_InitLibrary(HRTFMode hrtf)
if (!context)
{
debug(LOG_ERROR, "Couldn't open audio context.");

debug(LOG_SOUND, "close device");
if (alcCloseDevice(device) == ALC_FALSE)
{
debug(LOG_SOUND, "OpenAl could not close the audio device.");
}
device = nullptr;
return false;
}

Expand All @@ -194,6 +201,21 @@ bool sound_InitLibrary(HRTFMode hrtf)
if (err != ALC_NO_ERROR)
{
debug(LOG_ERROR, "Couldn't initialize audio context: %s", alcGetString(device, err));

alcGetError(device); // clear error codes

alcMakeContextCurrent(nullptr);
sound_GetContextError(device);
alcDestroyContext(context); // this gives a long delay on some impl.
context = nullptr;
sound_GetContextError(device);

debug(LOG_SOUND, "close device");
if (alcCloseDevice(device) == ALC_FALSE)
{
debug(LOG_SOUND, "OpenAl could not close the audio device.");
}
device = nullptr;
return false;
}

Expand Down Expand Up @@ -364,6 +386,7 @@ void sound_ShutdownLibrary(void)

debug(LOG_SOUND, "destroy previous context");
alcDestroyContext(context); // this gives a long delay on some impl.
context = nullptr;
sound_GetContextError(device);

debug(LOG_SOUND, "close device");
Expand Down
Loading