From e69d1b5a82fbc44103767c9e73b629218bf8f7d4 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sat, 12 May 2012 23:35:10 +0200 Subject: [PATCH] #767 related: fix sound resource management Use _smgr->release_buffer instead of direct alDeleteBuffers. --- simgear/sound/sample_group.cxx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index 069f85df..b0ddab8a 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -102,21 +102,19 @@ void SGSampleGroup::update( double dt ) { alSourceStop( source ); alGetSourcei( source, AL_SOURCE_STATE, &result ); } - if ( result == AL_STOPPED ) { - sample->no_valid_source(); - _smgr->release_source( sample->get_source() ); - } + } + if ( result == AL_STOPPED ) { + sample->no_valid_source(); + _smgr->release_source( source ); } } if ( result == AL_STOPPED ) { sample->stop(); - if ( !sample->is_queue() ) { - ALuint buffer = sample->get_buffer(); - // disconnect buffer from its source - otherwise it cannot be deleted - alSourceUnqueueBuffers(sample->get_source(), 1, &buffer); - alDeleteBuffers( 1, &buffer ); - testForALError("buffer remove"); + if (( !sample->is_queue() )&& + (sample->is_valid_buffer())) + { + _smgr->release_buffer(sample); } _removed_samples.erase( _removed_samples.begin()+i ); size--; @@ -181,7 +179,7 @@ void SGSampleGroup::update( double dt ) { alSourcePlay( source ); testForALError("sample play"); } else - SG_LOG( SG_SOUND, SG_ALERT, "No such buffer!\n"); + SG_LOG( SG_SOUND, SG_ALERT, "No such buffer!"); } } @@ -193,7 +191,7 @@ void SGSampleGroup::update( double dt ) { alGetSourcei( source, AL_SOURCE_STATE, &result ); if ( result == AL_STOPPED ) { - // sample is stoped because it wasn't looping + // sample is stopped because it wasn't looping sample->stop(); sample->no_valid_source(); _smgr->release_source( source ); -- 2.39.5