Skip to content

Commit

Permalink
feat: Fallback to null driver in defined one failed to load or open.
Browse files Browse the repository at this point in the history
  • Loading branch information
na2axl committed Nov 14, 2024
1 parent 368ed47 commit a3d965a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ gen/

# VCPKG
vcpkg_installed/
am_build/
23 changes: 18 additions & 5 deletions src/Core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ namespace SparkyStudios::Audio::Amplitude
{
if (_audioDriver = Driver::Find(config->driver()->str()); _audioDriver == nullptr)
{
amLogWarning("Could load the audio driver '%s'. Loading the default driver.", config->driver()->c_str());
amLogWarning("Could not load the audio driver '%s'. Loading the default driver.", config->driver()->c_str());
_audioDriver = Driver::Default();
}
}
Expand All @@ -679,7 +679,13 @@ namespace SparkyStudios::Audio::Amplitude

if (_audioDriver == nullptr)
{
amLogCritical("Could not load the audio driver.");
amLogError("Could not load the audio driver. Loading the null driver as fallback.");
_audioDriver = sNullDriverPlugin.get();
}

if (_audioDriver == nullptr)
{
amLogCritical("Failed to load the specified driver, the default driver, and the null driver. Please check your engine configuration, and ensure that all the needed plugins are loaded.");
Deinitialize();
return false;
}
Expand Down Expand Up @@ -815,11 +821,18 @@ namespace SparkyStudios::Audio::Amplitude
// Open the audio device through the driver
if (!_audioDriver->Open(_state->mixer.GetDeviceDescription()))
{
amLogCritical("Could not open the audio device.");
Deinitialize();
return false;
amLogError("Could not open the audio device using the '%s' driver. Loading the null driver as fallback.", _audioDriver->GetName().c_str());
_audioDriver = sNullDriverPlugin.get();

if (_audioDriver == nullptr || !_audioDriver->Open(_state->mixer.GetDeviceDescription()))
{
amLogCritical("Could not open the audio device.");
Deinitialize();
return false;
}
}

amLogDebug("Amplitude Engine initialized successfully.");
return true;
}

Expand Down

0 comments on commit a3d965a

Please sign in to comment.