From ce8b2974a3f93ec66995442329765084306b53f2 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 13 Feb 2016 11:09:37 +0200 Subject: [PATCH] Handle inability of OpenAL implementation to return number of available sources OpenAL specification doesn't require alcGetIntegerv() to return meaningful values for ALC_MONO_SOURCES and ALC_MONO_SOURCES. At least Apple's OpenAL implementation returns zeroes, although it can generate reasonable number of sources. --- src/sound/oalsound.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index 1eec34c1b..736893de7 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -781,7 +781,20 @@ OpenALSoundRenderer::OpenALSoundRenderer() alcGetIntegerv(Device, ALC_MONO_SOURCES, 1, &numMono); alcGetIntegerv(Device, ALC_STEREO_SOURCES, 1, &numStereo); - Sources.Resize(MIN(MAX(*snd_channels, 2), numMono+numStereo)); + // OpenAL specification doesn't require alcGetIntegerv() to return + // meaningful values for ALC_MONO_SOURCES and ALC_MONO_SOURCES. + // At least Apple's OpenAL implementation returns zeroes, + // although it can generate reasonable number of sources. + + const int numChannels = MAX(*snd_channels, 2); + int numSources = numMono + numStereo; + + if (0 == numSources) + { + numSources = numChannels; + } + + Sources.Resize(MIN(numChannels, numSources)); for(size_t i = 0;i < Sources.Size();i++) { alGenSources(1, &Sources[i]);