Skip to content

Commit f1a05d0

Browse files
authoredMay 5, 2020
Fix broken client if openal cannot be opened (#9804)
1 parent cad5b98 commit f1a05d0

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed
 

‎src/client/clientlauncher.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
105105
}
106106

107107
RenderingEngine::get_instance()->setupTopLevelWindow(PROJECT_NAME_C);
108-
108+
109109
/*
110110
This changes the minimum allowed number of vertices in a VBO.
111111
Default is 500.

‎src/client/game.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ bool Game::init(
12491249
bool Game::initSound()
12501250
{
12511251
#if USE_SOUND
1252-
if (g_settings->getBool("enable_sound")) {
1252+
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get()) {
12531253
infostream << "Attempting to use OpenAL audio" << std::endl;
12541254
sound = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher);
12551255
if (!sound)

‎src/client/sound_openal.cpp

+25-8
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,38 @@ class SoundManagerSingleton
275275
m_device(nullptr, delete_alcdevice),
276276
m_context(nullptr, delete_alccontext)
277277
{
278-
if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr), delete_alcdevice)))
279-
throw std::runtime_error("Audio: Global Initialization: Device Open");
278+
}
279+
280+
bool init()
281+
{
282+
if (!(m_device = unique_ptr_alcdevice(alcOpenDevice(nullptr), delete_alcdevice))) {
283+
errorstream << "Audio: Global Initialization: Failed to open device" << std::endl;
284+
return false;
285+
}
280286

281287
if (!(m_context = unique_ptr_alccontext(
282288
alcCreateContext(m_device.get(), nullptr), delete_alccontext))) {
283-
throw std::runtime_error("Audio: Global Initialization: Context Create");
289+
errorstream << "Audio: Global Initialization: Failed to create context" << std::endl;
290+
return false;
284291
}
285292

286-
if (!alcMakeContextCurrent(m_context.get()))
287-
throw std::runtime_error("Audio: Global Initialization: Context Current");
293+
if (!alcMakeContextCurrent(m_context.get())) {
294+
errorstream << "Audio: Global Initialization: Failed to make current context" << std::endl;
295+
return false;
296+
}
288297

289298
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
290299

291-
if (alGetError() != AL_NO_ERROR)
292-
throw std::runtime_error("Audio: Global Initialization: OpenAL Error");
300+
if (alGetError() != AL_NO_ERROR) {
301+
errorstream << "Audio: Global Initialization: OpenAL Error " << alGetError() << std::endl;
302+
return false;
303+
}
293304

294305
infostream << "Audio: Global Initialized: OpenAL " << alGetString(AL_VERSION)
295306
<< ", using " << alcGetString(m_device.get(), ALC_DEVICE_SPECIFIER)
296307
<< std::endl;
308+
309+
return true;
297310
}
298311

299312
~SoundManagerSingleton()
@@ -682,7 +695,11 @@ class OpenALSoundManager: public ISoundManager
682695

683696
std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton()
684697
{
685-
return std::shared_ptr<SoundManagerSingleton>(new SoundManagerSingleton());
698+
auto smg = std::make_shared<SoundManagerSingleton>();
699+
if (!smg->init()) {
700+
smg.reset();
701+
}
702+
return smg;
686703
}
687704

688705
ISoundManager *createOpenALSoundManager(SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher)

‎src/gui/guiEngine.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ GUIEngine::GUIEngine(JoystickController *joystick,
144144
//create soundmanager
145145
MenuMusicFetcher soundfetcher;
146146
#if USE_SOUND
147-
if (g_settings->getBool("enable_sound"))
147+
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get())
148148
m_sound_manager = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher);
149149
#endif
150-
if(!m_sound_manager)
150+
if (!m_sound_manager)
151151
m_sound_manager = &dummySoundManager;
152152

153153
//create topleft header

0 commit comments

Comments
 (0)
Please sign in to comment.