From 796427092998420fc2dd9dab8a12724479f27aab Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 22 Oct 2009 08:32:04 +0000 Subject: [PATCH] fix a memory leak and add some temporary debugging statements. --- simgear/sound/openal_test1.cxx | 2 ++ simgear/sound/sample_group.cxx | 8 +++++--- simgear/sound/sample_openal.cxx | 4 ++-- simgear/sound/soundmgr_openal.cxx | 8 ++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/simgear/sound/openal_test1.cxx b/simgear/sound/openal_test1.cxx index dd2a77f0..66678f8b 100644 --- a/simgear/sound/openal_test1.cxx +++ b/simgear/sound/openal_test1.cxx @@ -50,6 +50,7 @@ int main( int argc, char *argv[] ) { ALCdevice *dev; ALCcontext *context; + alutInit(&argc, argv); sglog().setLogLevels( SG_ALL, SG_ALERT ); // initialize OpenAL @@ -164,6 +165,7 @@ int main( int argc, char *argv[] ) { alSourcePlay( source ); sleep(10); + alutExit(); return 0; } diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index 5d460be1..cab19896 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -175,8 +175,8 @@ void SGSampleGroup::update( double dt ) { if ( !sample->is_playing() ) { // a request to stop playing the sound has been filed. - sample->no_valid_source(); sample->stop(); + sample->no_valid_source(); _smgr->release_source( sample->get_source() ); } else { update_sample_config( sample ); @@ -191,9 +191,10 @@ void SGSampleGroup::update( double dt ) { alGetSourcei( source, AL_SOURCE_STATE, &result ); if ( result == AL_STOPPED ) { // sample is stoped because it wasn't looping - sample->no_valid_source(); sample->stop(); + sample->no_valid_source(); _smgr->release_source( source ); + _smgr->release_buffer( sample ); } } testForALError("update"); @@ -223,7 +224,8 @@ bool SGSampleGroup::remove( const string &refname ) { return false; } - _removed_samples.push_back( sample_it->second ); + if ( sample_it->second->is_valid_buffer() ) + _removed_samples.push_back( sample_it->second ); _samples.erase( sample_it ); return true; diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 92acd8ad..c5ced562 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -183,11 +183,11 @@ void SGSoundSample::set_position( const SGGeod& pos ) { void SGSoundSample::update_absolute_position() { SGQuatd orient = SGQuatd::fromLonLat(_base_pos) * _orientation; _orivec = -toVec3f(orient.rotate(_direction)); -printf("ori: %f %f %f\n", _orivec[0], _orivec[1], _orivec[2]); +//printf("ori: %f %f %f\n", _orivec[0], _orivec[1], _orivec[2]); orient = SGQuatd::fromRealImag(0, _relative_pos) * _orientation; _absolute_pos = -SGVec3d::fromGeod(_base_pos); // -orient.rotate(SGVec3d::e1()); -printf("pos: %f %f %f\n", _absolute_pos[0], _absolute_pos[1], _absolute_pos[2]); +//printf("pos: %f %f %f\n", _absolute_pos[0], _absolute_pos[1], _absolute_pos[2]); } string SGSoundSample::random_string() { diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index ee5320da..9a49d547 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -94,6 +94,7 @@ SGSoundMgr::~SGSoundMgr() { // initialize the sound manager void SGSoundMgr::init() { +printf("Initializing OpenAL sound manager\n"); SG_LOG( SG_GENERAL, SG_INFO, "Initializing OpenAL sound manager" ); ALCdevice *device = alcOpenDevice(_devname); @@ -114,6 +115,8 @@ void SGSoundMgr::init() { return; } + if (_context != NULL) + SG_LOG(SG_GENERAL, SG_ALERT, "context is already assigned"); _context = context; _working = true; @@ -171,6 +174,7 @@ void SGSoundMgr::activate() { // stop the sound manager void SGSoundMgr::stop() { if (_working) { +printf("Stopping Sound Manager\n"); _working = false; _active = false; @@ -193,6 +197,7 @@ void SGSoundMgr::stop() { void SGSoundMgr::suspend() { if (_working) { +printf("SoundManager suspend\n"); sample_group_map_iterator sample_grp_current = _sample_groups.begin(); sample_group_map_iterator sample_grp_end = _sample_groups.end(); for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { @@ -205,6 +210,7 @@ void SGSoundMgr::suspend() { void SGSoundMgr::resume() { if (_working) { +printf("SoundManager resume\n"); sample_group_map_iterator sample_grp_current = _sample_groups.begin(); sample_group_map_iterator sample_grp_end = _sample_groups.end(); for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { @@ -217,6 +223,7 @@ void SGSoundMgr::resume() { void SGSoundMgr::bind () { +printf("SoundManager bind\n"); _free_sources.clear(); _free_sources.reserve( MAX_SOURCES ); _sources_in_use.clear(); @@ -226,6 +233,7 @@ void SGSoundMgr::bind () void SGSoundMgr::unbind () { +printf("SoundManager unbind\n"); _sample_groups.clear(); // delete free sources -- 2.39.5