Skip to content

Type the VQA errors and the on-disk chunks - #6

Open
mischa85 wants to merge 5 commits into
nativefrom
vqa-error
Open

Type the VQA errors and the on-disk chunks#6
mischa85 wants to merge 5 commits into
nativefrom
vqa-error

Conversation

@mischa85

@mischa85 mischa85 commented Sep 9, 2026

Copy link
Copy Markdown
Owner

Five commits, rebased onto native after the upstream merge. Starts as the
vqa-error-type branch and follows the types through the signatures and structs it
touches, so no line here spells long.

Four on-disk layout bugs

Each is 4 bytes per field on Win32 and 8 off it, so each breaks only on a 64-bit target.
Upstream added static_asserts for two of them in 945e858, and those asserts fail on any
other compiler; these commits make them hold everywhere.

structure was now
ChunkHeader two unsigned long, read with sizeof(chunk), so 16 bytes read where the file has 8 uint32_t, static_assert(== 8)
Foff long * frame offset table read raw from FINF, where the file stores 32-bit offsets uint32_t *
VQAHeader #pragma pack gated on _MSC_VER, plus two unsigned long: 56 bytes, asserted 42 packed everywhere, uint32_t, 42 on both
VQASN2J two long in the SN2J ADPCM state: 20 bytes, asserted 12 int32_t, 12 on both

REVERSE_LONG follows to uint32_t, and iff.h gains the <cstdint> it was relying on
transitively.

A 64-bit defect in the error path

VQA_SeekGroup declared unsigned int rc inside a long returning function, so a
negative error widened as unsigned:

input -9    before: 4294967295  (< 0? NO)     after: -1  (< 0? yes)

Every < 0 test on that result failed on a 64-bit build. Win32 lands on -1, which is why
it went unseen.

Signedness

The 26 VQAERR_ defines become enum VQAErrorType : int32_t, and the functions returning
them say so. Frame numbers are unsigned now, StopFrame included, and the 24 fields
around them follow.

Four stay signed because -1 is a live sentinel: LoopCache.Min and Max,
LoopStartFrame0, and the drawers LastFrameNum. Their comparison sites test the sentinel instead of relying on -1 reinterpreting as an impossible frame. The drawers is
the one that could not go unsigned at all: VQA_CalcFramesSinceDrawn orders against it
(cur >= LastFrameNum) and tests its subtraction for negativity.

Three x < NumFrames - 1 tests became x + 1 < NumFrames. The old signed types gave -1
for a zero frame count and the test was false; unsigned subtraction would have wrapped to
0xFFFFFFFF and made it true. The additive form keeps the original answer for every frame
count, checked exhaustively.

Verification

Nothing changes on the supported target: long is 32 bits on Win32, so every field keeps
its offset and width and both packed layouts keep the sizes they always had there. Both
Windows configurations are green.

No harness reaches these sources, so six vqalib files were compiled here against a
stubbed io.h: loader.cpp drops from 19 warnings to 14, and task.cpp, drawer.cpp,
buffer_.cpp and dstream.cpp sit exactly at their native counts. Nothing added.
audio.cpp keeps 2 errors, identical to native, from the Callback1/Callback2
function pointers assigned to void *.

No struct here is serialized and the library never writes, so there is no save or file
format to migrate.

Local: 20 harnesses unported as listed, 19 passing.

@mischa85 mischa85 added the no change record Mechanical change with no player- or modder-visible effect label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Development builds of 207c64f:

The links work without a GitHub account. Artifacts expire after 90 days, and this comment follows the latest successful build.

@mischa85 mischa85 changed the title Report VQA errors through a typed enum Type the VQA errors, frame numbers and chunk header Sep 9, 2026
@mischa85 mischa85 changed the title Type the VQA errors, frame numbers and chunk header Type the VQA errors and the on-disk chunks Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no change record Mechanical change with no player- or modder-visible effect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant