From 4811d41ec8a1de005ad7a6fb2b5d338d0890c038 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 15 Oct 2023 22:31:50 +0200 Subject: [PATCH] Fix calculating wrong chunk buffer window when only the block header is inside a chunk and all the data is in the next --- src/ObjWriting/ObjContainer/IPak/IPakWriter.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ObjWriting/ObjContainer/IPak/IPakWriter.cpp b/src/ObjWriting/ObjContainer/IPak/IPakWriter.cpp index 2dedce49..6767a64d 100644 --- a/src/ObjWriting/ObjContainer/IPak/IPakWriter.cpp +++ b/src/ObjWriting/ObjContainer/IPak/IPakWriter.cpp @@ -176,6 +176,11 @@ public: void StartNewBlock() { AlignToBlockHeader(); + + // Skip to the next chunk when only the header could fit into the current chunk anyway + if (static_cast(utils::Align(m_current_offset, static_cast(ipak_consts::IPAK_CHUNK_SIZE)) - m_current_offset) <= sizeof(IPakDataBlockHeader)) + FlushChunk(); + m_current_block_header_offset = m_current_offset; m_current_block = {}; m_current_block.countAndOffset.offset = static_cast(m_file_offset);