Skip to content

Commit

Permalink
openal_track: Improve failure handling
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Jul 5, 2024
1 parent 3f177bb commit e6c7946
Showing 1 changed file with 23 additions and 0 deletions.
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

0 comments on commit e6c7946

Please sign in to comment.