From eabea655c54298f2ddaf02f8556a18227cca01c6 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 e15c639af..47115e23e 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; +} ////////////////////////////////////////////////////////////