From 9605212f8c9b3590cd7a5e2c4b671a062d89b719 Mon Sep 17 00:00:00 2001 From: vittorioromeo Date: Sun, 9 Jun 2024 04:37:42 +0200 Subject: [PATCH] Update self-referential owner ptr when moving `SoundStream` --- src/SFML/Audio/SoundStream.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index e15c639afb..47115e23e5 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -211,7 +211,7 @@ struct SoundStream::Impl : priv::MiniaudioUtils::SoundBase // Member data //////////////////////////////////////////////////////////// static constexpr ma_data_source_vtable vtable{read, seek, getFormat, getCursor, getLength, setLooping, /* flags */ 0}; - SoundStream* const owner; //!< Owning SoundStream object + SoundStream* owner; //!< Owning SoundStream object std::vector sampleBuffer; //!< Our temporary sample buffer std::size_t sampleBufferCursor{}; //!< The current read position in the temporary sample buffer std::uint64_t samplesProcessed{}; //!< Number of samples processed since beginning of the stream @@ -234,11 +234,26 @@ SoundStream::~SoundStream() = default; //////////////////////////////////////////////////////////// -SoundStream::SoundStream(SoundStream&&) noexcept = default; +SoundStream::SoundStream(SoundStream&& rhs) noexcept : m_impl(std::move(rhs.m_impl)) +{ + // Update self-referential owner pointer. + m_impl->owner = this; +} //////////////////////////////////////////////////////////// -SoundStream& SoundStream::operator=(SoundStream&&) noexcept = default; +SoundStream& SoundStream::operator=(SoundStream&& rhs) noexcept +{ + if (this != &rhs) + { + m_impl = std::move(rhs.m_impl); + + // Update self-referential owner pointer. + m_impl->owner = this; + } + + return *this; +} ////////////////////////////////////////////////////////////