From 727217ce0a9765270551ad6e10a25ee0b7fb74e6 Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat@gmail.com>
Date: Sun, 1 Sep 2019 15:28:33 -0700
Subject: Ensure AL_STOPPED state change events are sent

With explicit calls to alSourceStop on a playing or paused source
---
 al/source.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

(limited to 'al/source.cpp')

diff --git a/al/source.cpp b/al/source.cpp
index 08e4bff6..010dee1c 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -2974,7 +2974,11 @@ START_API_FUNC
     BackendLockGuard __{*device->Backend};
     auto stop_source = [&context](ALsource *source) -> void
     {
+        /* Get the source state before clearing from the voice, so we know what
+         * state the source+voice was actually in.
+         */
         ALvoice *voice{GetSourceVoice(source, context.get())};
+        const ALenum oldstate{GetSourceState(source, voice)};
         if(voice != nullptr)
         {
             voice->mCurrentBuffer.store(nullptr, std::memory_order_relaxed);
@@ -2986,7 +2990,6 @@ START_API_FUNC
                 std::memory_order_acq_rel, std::memory_order_acquire);
             voice = nullptr;
         }
-        ALenum oldstate{GetSourceState(source, voice)};
         if(oldstate != AL_INITIAL && oldstate != AL_STOPPED)
         {
             source->state = AL_STOPPED;
@@ -3048,7 +3051,7 @@ START_API_FUNC
                 std::memory_order_acq_rel, std::memory_order_acquire);
             voice = nullptr;
         }
-        if(GetSourceState(source, voice) != AL_INITIAL)
+        if(source->state != AL_INITIAL)
         {
             source->state = AL_INITIAL;
             SendStateChangeEvent(context.get(), source->id, AL_INITIAL);
-- 
cgit v1.2.3