Fix crash on moving empty NetPacket

This commit is contained in:
Jérôme Leclercq
2018-09-25 14:53:49 +02:00
parent 602bdbe292
commit b6a33c76ca
3 changed files with 28 additions and 13 deletions

View File

@@ -27,6 +27,8 @@ namespace Nz
ByteStream(ByteStream&& stream) noexcept = default;
virtual ~ByteStream();
inline void ClearStream();
inline Endianness GetDataEndianness() const;
inline Nz::UInt64 GetSize() const;
inline Stream* GetStream() const;

View File

@@ -30,6 +30,18 @@ namespace Nz
NazaraWarning("Failed to flush bits at serializer destruction");
}
/*!
* \brief Reset stream
*/
inline void ByteStream::ClearStream()
{
// We don't want to lose some bits..
FlushBits();
m_context.stream = nullptr;
m_ownedStream.reset();
}
/*!
* \brief Gets the stream endianness
* \return Type of the endianness
@@ -113,22 +125,15 @@ namespace Nz
}
/*!
* \brief Sets this with a stream
* \brief Changes stream
*
* \param stream Stream existing
*
* \remark Produces a NazaraAssert if stream is invalid
*/
inline void ByteStream::SetStream(Stream* stream)
{
NazaraAssert(stream, "Invalid stream");
// We don't want to lose some bits..
FlushBits();
ClearStream();
m_context.stream = stream;
m_ownedStream.reset();
}
/*!