From e5eb5f8ed258e48515a4029ae06c17984d2f6383 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 12 Dec 2020 17:53:29 +0100 Subject: [PATCH] audio: Fix stop() not working for looped sound while sound is inactive Fixes #559 Also fixes #1031 for FMOD --- panda/src/audiotraits/fmodAudioSound.cxx | 6 ++++-- panda/src/audiotraits/openalAudioSound.cxx | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/panda/src/audiotraits/fmodAudioSound.cxx b/panda/src/audiotraits/fmodAudioSound.cxx index e81695969c..260228225a 100644 --- a/panda/src/audiotraits/fmodAudioSound.cxx +++ b/panda/src/audiotraits/fmodAudioSound.cxx @@ -259,6 +259,7 @@ stop() { } } _start_time = 0.0; + _paused = false; } @@ -827,12 +828,13 @@ set_active(bool active) { } else { // ...deactivate the sound. if (status() == PLAYING) { + PN_stdfloat time = get_time(); + stop(); if (get_loop_count() == 0) { // ...we're pausing a looping sound. _paused = true; - _start_time = get_time(); + _start_time = time; } - stop(); } } } diff --git a/panda/src/audiotraits/openalAudioSound.cxx b/panda/src/audiotraits/openalAudioSound.cxx index 087686a452..60319249b2 100644 --- a/panda/src/audiotraits/openalAudioSound.cxx +++ b/panda/src/audiotraits/openalAudioSound.cxx @@ -217,6 +217,8 @@ stop() { _stream_queued.resize(0); } + _paused = false; + _manager->stopping_sound(this); release_sound_data(false); } @@ -828,13 +830,13 @@ set_active(bool active) { } else { // ...deactivate the sound. if (status()==PLAYING) { - if (_loop_count==0) { - // ...we're pausing a looping sound. - _paused=true; - } // Store off the current time so we can resume from where we paused. _start_time = get_time(); stop(); + if (_loop_count == 0) { + // ...we're pausing a looping sound. + _paused = true; + } } } }