From 07aa70dce9a6a429a88cd8d9e77f4a228b35b24f Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Sun, 4 Dec 2011 17:18:02 +0100 Subject: [PATCH] sound: fix sound-buffer-in-use issue FGFX objects must be dereferenced early enough, and sound manager must be removed late enough - otherwise openal complains about resources being still in use when tryin to remove buffers. Also: do not create FGFX objects for AI/MP aircraft, when AI sound is disabled. --- src/AIModel/AIBase.cxx | 4 +++- src/Main/globals.cxx | 4 +++- src/Model/acmodel.cxx | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 95d023296..230837621 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -228,7 +228,7 @@ void FGAIBase::update(double dt) { pitch*speed ); _fx->set_velocity( velocity ); } - else if (_aimodel) + else if ((_aimodel)&&(fgGetBool("/sim/sound/aimodels/enabled",false))) { string fxpath = _aimodel->get_sound_path(); if (fxpath != "") @@ -492,6 +492,8 @@ void FGAIBase::unbind() { props->setBoolValue("/sim/controls/radar/", true); + // drop reference to sound effects now + _fx = 0; } double FGAIBase::UpdateRadar(FGAIManager* manager) { diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 00dd943dc..4eb26f21f 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -171,7 +171,8 @@ FGGlobals::~FGGlobals() ai->unbind(); delete ai; } - + SGSubsystem* sound = subsystem_mgr->remove("sound"); + subsystem_mgr->shutdown(); subsystem_mgr->unbind(); delete subsystem_mgr; @@ -205,6 +206,7 @@ FGGlobals::~FGGlobals() delete tacanlist; delete carrierlist; delete channellist; + delete sound; } diff --git a/src/Model/acmodel.cxx b/src/Model/acmodel.cxx index 3c9faaf23..3b0658b0a 100644 --- a/src/Model/acmodel.cxx +++ b/src/Model/acmodel.cxx @@ -91,6 +91,9 @@ FGAircraftModel::reinit() void FGAircraftModel::deinit() { + // drop reference + _fx = 0; + if (!_aircraft) { return; }