From f1a05d0f71d69641fd954daf68d13acad91114f1 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Tue, 5 May 2020 08:38:18 +0200 Subject: Fix broken client if openal cannot be opened (#9804) --- src/client/sound_openal.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/client/sound_openal.cpp') diff --git a/src/client/sound_openal.cpp b/src/client/sound_openal.cpp index d0f935a7a..20a651c1d 100644 --- a/src/client/sound_openal.cpp +++ b/src/client/sound_openal.cpp @@ -275,25 +275,38 @@ public: m_device(nullptr, delete_alcdevice), m_context(nullptr, delete_alccontext) { - if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr), delete_alcdevice))) - throw std::runtime_error("Audio: Global Initialization: Device Open"); + } + + bool init() + { + if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr), delete_alcdevice))) { + errorstream << "Audio: Global Initialization: Failed to open device" << std::endl; + return false; + } if (!(m_context = unique_ptr_alccontext( alcCreateContext(m_device.get(), nullptr), delete_alccontext))) { - throw std::runtime_error("Audio: Global Initialization: Context Create"); + errorstream << "Audio: Global Initialization: Failed to create context" << std::endl; + return false; } - if (!alcMakeContextCurrent(m_context.get())) - throw std::runtime_error("Audio: Global Initialization: Context Current"); + if (!alcMakeContextCurrent(m_context.get())) { + errorstream << "Audio: Global Initialization: Failed to make current context" << std::endl; + return false; + } alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); - if (alGetError() != AL_NO_ERROR) - throw std::runtime_error("Audio: Global Initialization: OpenAL Error"); + if (alGetError() != AL_NO_ERROR) { + errorstream << "Audio: Global Initialization: OpenAL Error " << alGetError() << std::endl; + return false; + } infostream << "Audio: Global Initialized: OpenAL " << alGetString(AL_VERSION) << ", using " << alcGetString(m_device.get(), ALC_DEVICE_SPECIFIER) << std::endl; + + return true; } ~SoundManagerSingleton() @@ -682,7 +695,11 @@ public: std::shared_ptr createSoundManagerSingleton() { - return std::shared_ptr(new SoundManagerSingleton()); + auto smg = std::make_shared(); + if (!smg->init()) { + smg.reset(); + } + return smg; } ISoundManager *createOpenALSoundManager(SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher) -- cgit v1.2.3