From 5407fe2518187975d7acc3147fa6ce4a2b4f42fb Mon Sep 17 00:00:00 2001 From: vl Date: Wed, 1 Jun 2011 00:04:11 +0200 Subject: [PATCH] Fixed: ugly fix to not crash when we cannot create a buffer #1116 --- .../nel/src/sound/driver/openal/source_al.cpp | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/code/nel/src/sound/driver/openal/source_al.cpp b/code/nel/src/sound/driver/openal/source_al.cpp index f156bfb7c..050081df1 100644 --- a/code/nel/src/sound/driver/openal/source_al.cpp +++ b/code/nel/src/sound/driver/openal/source_al.cpp @@ -890,15 +890,22 @@ void CSourceAL::setStreamingBuffersMax(uint buffers) unqueueBuffers(); removeBuffers(); - for(uint i = 0; i < _BuffersMax; ++i) - { - // create a new buffer - CBufferAL *buffer = static_cast(_SoundDriver->createBuffer()); - // use StorageSoftware because buffers will be reused - // deleting and recreating them is a waste of time - buffer->setStorageMode(IBuffer::StorageSoftware); - _Buffers[buffer->bufferName()] = buffer; - } + for(uint i = 0; i < _BuffersMax; ++i) + { + try { + // create a new buffer + CBufferAL *buffer = static_cast(_SoundDriver->createBuffer()); + // use StorageSoftware because buffers will be reused + // deleting and recreating them is a waste of time + buffer->setStorageMode(IBuffer::StorageSoftware); + _Buffers[buffer->bufferName()] = buffer; + } catch(ESoundDriverGenBuf &e) { + nlwarning("Cannot create %d buffers. openal fails after %d buffers", buffers, i); + _BuffersMax = i; + _BuffersName.resize(i); + break; + } + } } /// Set the default size for streaming buffers