Skip to content

Commit

Permalink
Update self-referential owner ptr when moving SoundStream
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Jun 10, 2024
1 parent a303cee commit eabea65
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/SFML/Audio/SoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::int16_t> 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
Expand All @@ -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;
}


////////////////////////////////////////////////////////////
Expand Down

0 comments on commit eabea65

Please sign in to comment.