Skip to content

Commit

Permalink
Make padding consistent on all operating systems
Browse files Browse the repository at this point in the history
Seeking beyond the end of the stream doesn't necesarily pad it. Some versions of operating systems or platforms might yield different behavior. On my system, this occasionally failed, especially when the positive seek offset from the end of the stream was large. Changed any padding behavior with an actual cheap Pad() call to make sure this will never be an issue.
  • Loading branch information
Mauler125 committed Dec 28, 2024
1 parent b9db04f commit 4706c25
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions src/logic/pakfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void CPakFileBuilder::AddStreamingDataEntry(PakStreamSetEntry_s& block, const ui
if (paddedSize > block.dataSize)
{
const size_t paddingRemainder = paddedSize - block.dataSize;
out.SeekPut(paddingRemainder, std::ios::cur);
out.Pad(paddingRemainder);
}

size_t& nextOffsetCounter = isMandatory ? m_nextMandatoryStarpakOffset : m_nextOptionalStarpakOffset;
Expand Down Expand Up @@ -868,10 +868,5 @@ void CPakFileBuilder::BuildFromMap(const string& mapPath)
Log("Written pak file \"%s\" with %zu assets, totaling %zd bytes.\n",
m_pakFilePath.c_str(), GetAssetCount(), totalPakSize);

// if we had pages which we ended up padding out to match the alignment,
// then we need to seek back to the end of the file; SeekPut only writes
// up to len if we either write after it again, or close the stream when
// the SeekPut cursor is at that location.
out.SeekPut(totalPakSize);
out.Close();
}
2 changes: 1 addition & 1 deletion src/logic/pakpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void CPakPageBuilder::WritePageData(BinaryIO& out) const
// - pad out the previous asset to align our current asset.
// - pad out the current asset to its full aligned size.
// - pad out the page to its full aligned size.
out.SeekPut(lump.size, std::ios::cur);
out.Pad(lump.size);
}
}
}
Expand Down

0 comments on commit 4706c25

Please sign in to comment.