Allow game to run with GUI while without audio.

This commit is contained in:
Evan Haataja 2020-08-25 02:35:59 +00:00 committed by Tulio Leao
parent fbeff35aec
commit 3127a4dc64
2 changed files with 12 additions and 2 deletions

View File

@ -9,6 +9,7 @@
#include "Ui.h"
#include "SDLException.h"
#include "UiContext.h"
#include "audio/AudioContext.h"
#include "drawing/BitmapReader.h"
@ -55,7 +56,16 @@ int main(int argc, const char** argv)
{
// Run OpenRCT2 with a UI context
auto env = ToShared(CreatePlatformEnvironment());
auto audioContext = ToShared(CreateAudioContext());
std::shared_ptr<IAudioContext> audioContext;
try
{
audioContext = ToShared(CreateAudioContext());
}
catch (const SDLException&)
{
log_warning("Failed to create audio context. Using dummy audio context.");
audioContext = ToShared(CreateDummyAudioContext());
}
auto uiContext = ToShared(CreateUiContext(env));
context = CreateContext(env, audioContext, uiContext);
}

View File

@ -1447,7 +1447,7 @@ private:
rct_string_id audioDeviceStringId = STR_OPTIONS_SOUND_VALUE_DEFAULT;
const char* audioDeviceName = nullptr;
const int32_t currentDeviceIndex = OpenRCT2::Audio::GetCurrentDeviceIndex();
if (currentDeviceIndex == -1)
if (currentDeviceIndex == -1 || OpenRCT2::Audio::GetDeviceCount() == 0)
{
audioDeviceStringId = STR_SOUND_NONE;
}