Skip to content

gx: don't underflow the index reservation for fans/strips with fewer than 3 vertices - #301

Open
yacineolivier-maker wants to merge 1 commit into
encounter:mainfrom
yacineolivier-maker:fix-strip-fan-index-reserve
Open

yacineolivier-maker wants to merge 1 commit into
encounter:mainfrom
yacineolivier-maker:fix-strip-fan-index-reserve

Conversation

@yacineolivier-maker

@yacineolivier-maker yacineolivier-maker commented Oct 29, 2026 •

Copy link
Copy Markdown

prepare_idx_buffer reserves ((u32(vtxCount) - 3) * 3 + 3) * sizeof(u16) bytes for triangle fans and strips. With 0-2 vertices the subtraction wraps around, so reserve_extra asks for about 8 GiB. Degenerate primitives like that are valid GX. Super Mario Galaxy emits them, and we hit this while porting it to PC.

The fix reserves vtxCount indices when there are fewer than 3 vertices, and computes in size_t otherwise. The loops that follow are unchanged; they emit no triangle for such primitives.

We've carried this patch in a Super Mario Galaxy PC port (https://github.com/yacineolivier-maker/petari-pc) for several weeks. That port, this patch and this description were written with AI assistance (Claude).

…than 3 vertices

(u32(vtxCount) - 3) wraps around for 0-2 vertices, so reserve_extra asks for about 8 GiB.
Degenerate primitives like these are legal GX and some games emit them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant