Skip to content

Commit 46707cd

Browse files
vtfpp: fix writing value as uint64 instead of uint32
1 parent 21e8600 commit 46707cd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/vtfpp/VTF.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ VTF::VTF(std::vector<std::byte>&& vtfData, bool parseHeaderOnly)
346346

347347
// Sort resources by their offset, in case certain VTFs are written
348348
// weirdly and have resource data written out of order. So far I have
349-
// found only one VTF in an official Valve game where this is the case
349+
// found only one VTF in an official Valve game where this is the case.
350+
// UPDATE: We do this intentionally to write image data at the end now!
351+
// It fixes mip skipping issues, and should still work fine in every branch.
350352
std::ranges::sort(this->resources, [](const Resource& lhs, const Resource& rhs) {
351353
if ((lhs.flags & Resource::FLAG_LOCAL_DATA) && (rhs.flags & Resource::FLAG_LOCAL_DATA)) {
352354
return lhs.type < rhs.type;
@@ -2118,7 +2120,7 @@ std::vector<std::byte> VTF::bake() const {
21182120
writer.write(resource.data);
21192121
resourceHeaderCurPos = writer.tell();
21202122
} else {
2121-
writer.write(resourceDataCurPos);
2123+
writer.write<uint32_t>(resourceDataCurPos);
21222124
resourceHeaderCurPos = writer.tell();
21232125
writer.seek_u(resourceDataCurPos).write(resource.data);
21242126
resourceDataCurPos = writer.tell();

0 commit comments

Comments
 (0)