From a10cd7d8bb454544fb3800db4dec451fb6d5123c Mon Sep 17 00:00:00 2001 From: Sam Edwards Date: Fri, 2 Mar 2018 00:53:10 -0700 Subject: [PATCH] openal: Always use release_sound_data This simplifies cleanup() a little bit. --- panda/src/audiotraits/openalAudioSound.I | 11 +++++++++-- panda/src/audiotraits/openalAudioSound.cxx | 7 +++---- panda/src/audiotraits/openalAudioSound.h | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/panda/src/audiotraits/openalAudioSound.I b/panda/src/audiotraits/openalAudioSound.I index 6263872e1a..03592adfde 100644 --- a/panda/src/audiotraits/openalAudioSound.I +++ b/panda/src/audiotraits/openalAudioSound.I @@ -55,10 +55,17 @@ require_sound_data() { /** * Checks if the sound data record is present and releasable, and if so, * releases it. + * + * The sound data is "releasable" if it's from an ordinary, local file. Remote + * streams cannot necessarily be reopened if lost, so we'll hold onto them if + * so. The `force` argument overrides this, indicating we don't intend to + * reacquire the sound data. */ void OpenALAudioSound:: -release_sound_data() { - if ((_sd!=0) && (!_movie->get_filename().empty())) { +release_sound_data(bool force) { + if (!has_sound_data()) return; + + if (force || !_movie->get_filename().empty()) { _manager->decrement_client_count(_sd); _sd = 0; } diff --git a/panda/src/audiotraits/openalAudioSound.cxx b/panda/src/audiotraits/openalAudioSound.cxx index d257fefd72..628a3a2279 100644 --- a/panda/src/audiotraits/openalAudioSound.cxx +++ b/panda/src/audiotraits/openalAudioSound.cxx @@ -80,7 +80,7 @@ OpenALAudioSound(OpenALAudioManager* manager, audio_warning("stereo sound " << movie->get_filename() << " will not be spatialized"); } } - release_sound_data(); + release_sound_data(false); } @@ -106,8 +106,7 @@ cleanup() { stop(); } if (has_sound_data()) { - _manager->decrement_client_count(_sd); - _sd = 0; + release_sound_data(true); } _manager->release_sound(this); _manager = 0; @@ -219,7 +218,7 @@ stop() { } _manager->stopping_sound(this); - release_sound_data(); + release_sound_data(false); } /** diff --git a/panda/src/audiotraits/openalAudioSound.h b/panda/src/audiotraits/openalAudioSound.h index b44a889445..e10f4f179a 100644 --- a/panda/src/audiotraits/openalAudioSound.h +++ b/panda/src/audiotraits/openalAudioSound.h @@ -117,7 +117,7 @@ private: void pull_used_buffers(); void push_fresh_buffers(); INLINE bool require_sound_data(); - INLINE void release_sound_data(); + INLINE void release_sound_data(bool force); INLINE bool is_valid() const; INLINE bool is_playing() const;