fix crash at shutdown

This commit is contained in:
David Rose 2009-12-30 01:18:44 +00:00
parent 478909b764
commit a180898666
5 changed files with 39 additions and 5 deletions

View File

@ -441,6 +441,8 @@ class ShowBase(DirectObject.DirectObject):
if getattr(self, 'musicManager', None): if getattr(self, 'musicManager', None):
self.musicManager.shutdown() self.musicManager.shutdown()
self.musicManager = None self.musicManager = None
for sfxManager in self.sfxManagerList:
sfxManager.shutdown()
self.sfxManagerList = [] self.sfxManagerList = []
if getattr(self, 'loader', None): if getattr(self, 'loader', None):
self.loader.destroy() self.loader.destroy()

View File

@ -679,8 +679,9 @@ release_sound(MilesAudioSound *audioSound) {
<<audioSound->get_name()<<"\"), this = " << (void *)this); <<audioSound->get_name()<<"\"), this = " << (void *)this);
LightReMutexHolder holder(_lock); LightReMutexHolder holder(_lock);
AudioSet::iterator ai = _sounds_on_loan.find(audioSound); AudioSet::iterator ai = _sounds_on_loan.find(audioSound);
nassertv(ai != _sounds_on_loan.end()); if (ai != _sounds_on_loan.end()) {
_sounds_on_loan.erase(ai); _sounds_on_loan.erase(ai);
}
audio_debug("MilesAudioManager::release_sound() finished"); audio_debug("MilesAudioManager::release_sound() finished");
} }
@ -702,8 +703,10 @@ cleanup() {
} }
// Be sure to cleanup associated sounds before cleaning up the manager: // Be sure to cleanup associated sounds before cleaning up the manager:
AudioSet orig_sounds;
orig_sounds.swap(_sounds_on_loan);
AudioSet::iterator ai; AudioSet::iterator ai;
for (ai = _sounds_on_loan.begin(); ai != _sounds_on_loan.end(); ++ai) { for (ai = orig_sounds.begin(); ai != orig_sounds.end(); ++ai) {
(*ai)->cleanup(); (*ai)->cleanup();
} }

View File

@ -60,7 +60,6 @@ MilesAudioSample::
~MilesAudioSample() { ~MilesAudioSample() {
miles_audio_debug("~MilesAudioSample()"); miles_audio_debug("~MilesAudioSample()");
cleanup(); cleanup();
_manager->release_sound(this);
miles_audio_debug("~MilesAudioSample() done"); miles_audio_debug("~MilesAudioSample() done");
} }
@ -123,6 +122,10 @@ play() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void MilesAudioSample:: void MilesAudioSample::
stop() { stop() {
if (_manager == (MilesAudioManager *)NULL) {
return;
}
miles_audio_debug("stop()"); miles_audio_debug("stop()");
_manager->stopping_sound(this); _manager->stopping_sound(this);
// The _paused flag should not be cleared here. _paused is not like // The _paused flag should not be cleared here. _paused is not like
@ -279,6 +282,13 @@ status() const {
void MilesAudioSample:: void MilesAudioSample::
cleanup() { cleanup() {
stop(); stop();
set_active(false);
nassertv(_sample == 0);
if (_manager != (MilesAudioManager *)NULL) {
_manager->release_sound(this);
_manager = NULL;
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -567,6 +577,9 @@ finish_callback(HSAMPLE sample) {
milesAudio_cat.debug() milesAudio_cat.debug()
<< "finished " << *self << "\n"; << "finished " << *self << "\n";
} }
if (self->_manager == (MilesAudioManager *)NULL) {
return;
}
self->_manager->_sounds_finished = true; self->_manager->_sounds_finished = true;
} }

View File

@ -152,6 +152,10 @@ set_time(float time) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void MilesAudioSound:: void MilesAudioSound::
set_active(bool active) { set_active(bool active) {
if (_manager == (MilesAudioManager *)NULL) {
return;
}
miles_audio_debug("set_active(active="<<active<<")"); miles_audio_debug("set_active(active="<<active<<")");
if (_active != active) { if (_active != active) {
_active = active; _active = active;

View File

@ -54,7 +54,6 @@ MilesAudioStream::
miles_audio_debug("~MilesAudioStream()"); miles_audio_debug("~MilesAudioStream()");
cleanup(); cleanup();
_manager->release_sound(this);
miles_audio_debug("~MilesAudioStream() done"); miles_audio_debug("~MilesAudioStream() done");
} }
@ -129,6 +128,9 @@ play() {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void MilesAudioStream:: void MilesAudioStream::
stop() { stop() {
if (_manager == (MilesAudioManager *)NULL) {
return;
}
miles_audio_debug("stop()"); miles_audio_debug("stop()");
_manager->stopping_sound(this); _manager->stopping_sound(this);
@ -286,6 +288,13 @@ cleanup() {
if (_stream) { if (_stream) {
stop(); stop();
} }
set_active(false);
nassertv(_stream == 0);
if (_manager != (MilesAudioManager *)NULL) {
_manager->release_sound(this);
_manager = NULL;
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -301,6 +310,9 @@ finish_callback(HSTREAM stream) {
milesAudio_cat.debug() milesAudio_cat.debug()
<< "finished " << *self << "\n"; << "finished " << *self << "\n";
} }
if (self->_manager == (MilesAudioManager *)NULL) {
return;
}
self->_manager->_sounds_finished = true; self->_manager->_sounds_finished = true;
} }