Browse Source

Source:play now returns false if alSourcePlay failed

Alex Szpakowski 11 years ago
parent
commit
33f12a6091

+ 1 - 3
src/modules/audio/openal/Pool.cpp

@@ -161,9 +161,7 @@ bool Pool::play(Source *source, ALuint &out)
 
 
 			source->retain();
 			source->retain();
 
 
-			source->playAtomic();
-
-			ok = true;
+			ok = source->playAtomic();
 		}
 		}
 		else
 		else
 		{
 		{

+ 10 - 1
src/modules/audio/openal/Source.cpp

@@ -513,7 +513,7 @@ bool Source::isLooping() const
 	return looping;
 	return looping;
 }
 }
 
 
-void Source::playAtomic()
+bool Source::playAtomic()
 {
 {
 	if (type == TYPE_STATIC)
 	if (type == TYPE_STATIC)
 	{
 	{
@@ -540,10 +540,19 @@ void Source::playAtomic()
 	// of the new one.
 	// of the new one.
 	reset();
 	reset();
 
 
+	// Clear errors.
+	alGetError();
+
 	alSourcePlay(source);
 	alSourcePlay(source);
 
 
+	// alSourcePlay may fail if the system has reached its limit of simultaneous
+	// playing sources.
+	bool success = alGetError() == AL_NO_ERROR;
+
 	valid = true; //if it fails it will be set to false again
 	valid = true; //if it fails it will be set to false again
 	//but this prevents a horrible, horrible bug
 	//but this prevents a horrible, horrible bug
+
+	return success;
 }
 }
 
 
 void Source::stopAtomic()
 void Source::stopAtomic()

+ 1 - 1
src/modules/audio/openal/Source.h

@@ -118,7 +118,7 @@ public:
 	virtual float getMaxDistance() const;
 	virtual float getMaxDistance() const;
 	virtual int getChannels() const;
 	virtual int getChannels() const;
 
 
-	void playAtomic();
+	bool playAtomic();
 	void stopAtomic();
 	void stopAtomic();
 	void pauseAtomic();
 	void pauseAtomic();
 	void resumeAtomic();
 	void resumeAtomic();