Quellcode durchsuchen

Handle no audio devices more gracefully

BearishSun vor 8 Jahren
Ursprung
Commit
1fe35a9644
1 geänderte Dateien mit 13 neuen und 10 gelöschten Zeilen
  1. 13 10
      Source/BansheeOpenAudio/Source/BsOAAudio.cpp

+ 13 - 10
Source/BansheeOpenAudio/Source/BsOAAudio.cpp

@@ -62,10 +62,7 @@ namespace bs
 			mDevice = alcOpenDevice(nullptr);
 
 		if (mDevice == nullptr)
-		{
-			BS_EXCEPT(InternalErrorException, "Failed to open OpenAL device: " + defaultDeviceName);
-			return;
-		}
+			LOGERR("Failed to open OpenAL device: " + defaultDeviceName);
 
 		rebuildContexts();
 	}
@@ -75,7 +72,8 @@ namespace bs
 		assert(mListeners.size() == 0 && mSources.size() == 0); // Everything should be destroyed at this point
 		clearContexts();
 
-		alcCloseDevice(mDevice);
+		if(mDevice != nullptr)
+			alcCloseDevice(mDevice);
 	}
 
 	void OAAudio::setVolume(float volume)
@@ -123,22 +121,24 @@ namespace bs
 
 		clearContexts();
 
-		alcCloseDevice(mDevice);
+		if(mDevice != nullptr)
+			alcCloseDevice(mDevice);
+		
 		mActiveDevice = device;
 
 		String narrowName = toString(device.name);
 		mDevice = alcOpenDevice(narrowName.c_str());
 		if (mDevice == nullptr)
-		{
-			BS_EXCEPT(InternalErrorException, "Failed to open OpenAL device: " + narrowName);
-			return;
-		}
+			LOGERR("Failed to open OpenAL device: " + narrowName);
 
 		rebuildContexts();
 	}
 
 	bool OAAudio::_isExtensionSupported(const String& extension) const
 	{
+		if (mDevice == nullptr)
+			return false;
+
 		if ((extension.length() > 2) && (extension.substr(0, 3) == "ALC"))
 			return alcIsExtensionPresent(mDevice, extension.c_str()) != AL_FALSE;
 		else
@@ -230,6 +230,9 @@ namespace bs
 
 		clearContexts();
 
+		if (mDevice == nullptr)
+			return;
+
 		UINT32 numListeners = (UINT32)mListeners.size();
 		UINT32 numContexts = numListeners > 1 ? numListeners : 1;