fix a memory leak and add some temporary debugging statements.

This commit is contained in:
ehofman
2009-10-22 08:32:04 +00:00
committed by Tim Moore
parent ea513d392e
commit 7964270929
4 changed files with 17 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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