@@ -275,25 +275,38 @@ class SoundManagerSingleton
275
275
m_device (nullptr , delete_alcdevice),
276
276
m_context (nullptr , delete_alccontext)
277
277
{
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
+ }
280
286
281
287
if (!(m_context = unique_ptr_alccontext (
282
288
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 ;
284
291
}
285
292
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
+ }
288
297
289
298
alDistanceModel (AL_INVERSE_DISTANCE_CLAMPED);
290
299
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
+ }
293
304
294
305
infostream << " Audio: Global Initialized: OpenAL " << alGetString (AL_VERSION)
295
306
<< " , using " << alcGetString (m_device.get (), ALC_DEVICE_SPECIFIER)
296
307
<< std::endl;
308
+
309
+ return true ;
297
310
}
298
311
299
312
~SoundManagerSingleton ()
@@ -682,7 +695,11 @@ class OpenALSoundManager: public ISoundManager
682
695
683
696
std::shared_ptr<SoundManagerSingleton> createSoundManagerSingleton ()
684
697
{
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;
686
703
}
687
704
688
705
ISoundManager *createOpenALSoundManager (SoundManagerSingleton *smg, OnDemandSoundFetcher *fetcher)
0 commit comments