diff --git a/src/ZoneLoading/Loading/ZoneDataPeeking.cpp b/src/ZoneLoading/Loading/ZoneDataPeeking.cpp index 9798c95b..212021b3 100644 --- a/src/ZoneLoading/Loading/ZoneDataPeeking.cpp +++ b/src/ZoneLoading/Loading/ZoneDataPeeking.cpp @@ -7,12 +7,18 @@ ZoneDataPeeking::ZoneDataPeeking(std::istream& stream) void ZoneDataPeeking::PeekWithStream(const std::function& cb) const { + const auto previousBits = m_stream.rdstate(); + // Clear any bits set previously + m_stream.clear(); + const auto previousPos = m_stream.tellg(); m_stream.seekg(0, std::ios::beg); cb(m_stream); + m_stream.clear(); m_stream.seekg(previousPos); + m_stream.setstate(previousBits); } void ZoneDataPeeking::EnsureHasEnoughData(const size_t size) diff --git a/src/ZoneLoading/ZoneLoading.cpp b/src/ZoneLoading/ZoneLoading.cpp index 4fbaba13..989f8e47 100644 --- a/src/ZoneLoading/ZoneLoading.cpp +++ b/src/ZoneLoading/ZoneLoading.cpp @@ -36,6 +36,9 @@ std::expected, std::string> ZoneLoading::LoadZone(const st if (!zoneLoader) return std::unexpected(std::format("Could not create factory for zone '{}'.", zoneName)); + // We may have to clear a fail bit if the peeking resulted in eof. + // Otherwise, we cannot seek. + file.clear(); // Revert to beginning to make sure no peeking has advanced the read position. // (As different peeking logic may advance by different amounts of bytes). file.seekg(0, std::ios::beg);