From 3c9fec78fa8b3c463e58ae3b291bb4a0ab25a189 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Wed, 23 Nov 2011 09:41:13 +0100 Subject: [PATCH] Slightly rearrange the buffer removing code. This should make sure the source is always stopped (required by the OpenAL spec) before a buffer is removed and added to the free source list. --- simgear/sound/sample_group.cxx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index 1610d088..1af1f268 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -94,12 +94,19 @@ void SGSampleGroup::update( double dt ) { ALint result = AL_STOPPED; if ( sample->is_valid_source() ) { + int source = sample->get_source(); + + alGetSourcei( source, AL_SOURCE_STATE, &result ); if ( sample->is_looping() ) { - sample->no_valid_source(); - _smgr->release_source( sample->get_source() ); + if ( result != AL_STOPPED ) { + alSourceStop( source ); + alGetSourcei( source, AL_SOURCE_STATE, &result ); + } + if ( result == AL_STOPPED ) { + sample->no_valid_source(); + _smgr->release_source( sample->get_source() ); + } } - else - alGetSourcei( sample->get_source(), AL_SOURCE_STATE, &result ); } if ( result == AL_STOPPED ) {