Skip to content

fix(libSceFont): render a glyph into a zero-extent surface to measure it - #9992

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
klosixgaming-arch:fix/font-zero-extent-surface
Oct 23, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
klosixgaming-arch:fix/font-zero-extent-surface

Conversation

@klosixgaming-arch

Copy link
Copy Markdown
Contributor

What

sceFontRenderCharGlyphImage and its Horizontal and Vertical forms returned SCE_FONT_ERROR_NO_SUPPORT_SURFACE for any surface whose width, height or row stride is 0, and cleared the metrics. A title that sizes a string before it has a surface to draw into initialises a surface with width 0 and renders each character only to read the metrics back. Every one of those calls failed, so the title never saw an advance.

This accepts a surface whose width or height is 0: the glyph metrics and image metrics are returned, the update rectangle is empty and nothing is written to the buffer. A zero stride is accepted only together with a zero width or height. A negative width, height or stride, a null buffer and a pixel size other than 1 or 4 bytes still return SCE_FONT_ERROR_NO_SUPPORT_SURFACE.

Evidence

Tekken Dark Resurrection, the PSP classic that runs in the PSPHD emulator on PS5 (tekken in my test folder). Logging the return value of every sceFont call it makes, 68 calls of sceFontRenderCharGlyphImageHorizontal before the first stop all returned 0x80460050, each with a surface of buffer set, width 0, height 31, row stride 0, one byte per pixel and a scissor of 0,0,0,31. With this change the same 68 calls return 0 with real metrics (for example 'C' advance 19.14, width 16.33, height 22.77).

The exact console result for a zero-extent surface is not measured. It is inferred from the title doing this on a console; the debt note says so.

This does not unblock Tekken. It still stops with Could not get surface summary (8a6c000b) at the same place, and I have not yet found why the string it sizes ends up with width 0 afterwards. I am sending this separately because the failing return code is wrong on its own and is easy to verify.

Related open PR

#8250 (reject undersized render surface strides) validates the stride of surfaces whose width and height are positive and explicitly returns early for the rest, so the two do not overlap in behaviour. Both add a line to docs/dev/debt/libSceFont.md, so whichever merges second needs a trivial documentation rebase.

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0, main 8fbafb82b0 plus this change: libs and relinker build; guest_font, guest_system_font, guest_font_writing_line, font_face_lifetime, font_face_lifetime_replace and font_face_lifetime_churn pass (6 of 6); tools/check_conventions.py passes.

The new checks are in GuestSystemFont.cpp: a surface of width 0 and stride 0, and one of height 0, return SCE_FONT_OK with the same advance as a normal surface, an empty update rectangle and an untouched buffer; a negative width, a zero stride with positive extent and a null buffer still return SCE_FONT_ERROR_NO_SUPPORT_SURFACE. Without the change to Layout.cpp guest_system_font fails at the first of these (I built it that way to check).

Checklist

  • Based on current main; open PR fix(libSceFont): accept overlapping render surface rows #8250 touches the same validation for a different case (see above)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: nothing yet (Tekken Dark Resurrection still stops later, see above)
  • AI-assisted: yes

AI-assisted: yes. Written with AI assistance and reviewed by me.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QLz9JYSXCPssYHgRW1CxJH

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head c002415 against current base 8fbafb82b03473eba4197436852bead4a291f15b. The validation change accepts zero width or height (including zero stride only for an empty extent) while still rejecting negative dimensions/stride, zero stride on a nonempty surface, null buffers, and unsupported pixel sizes. The new regression assertions check returned metrics, an empty update rectangle, and an untouched buffer. I found no blocking issue in the diff.

The author reports successful Windows builds of libs and relinker, six focused font tests, and passing conventions. CI eligibility, conventions, intake, labels, and report checks pass; hosted product builds are skipped. I did not rerun the font test locally: the available configured build uses the older /marc/AnyPS5 source tree, and the root filesystem is full, so it cannot provide an exact-head build here. The PR documents that zero-extent behavior is inferred from the title's calls and is not measured on a console.

@github-actions

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8250 docs/dev/debt/libSceFont.md L4

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5209 docs/dev/debt/libSceFont.md
PR 6044 core/libs/tests/GuestSystemFont.cpp

@klosixgaming-arch

Copy link
Copy Markdown
Contributor Author

Evidence from running a title with this change: TEKKEN: DARK RESURRECTION (PPSA31371) stops with Could not get surface summary (8a6c000b) without it. With this PR and #10021 both applied on top of main at 9d6adeb it gets past that point, plays its intro, and reaches the start menu, character select and a fight at about 55 fps by eye. Either PR alone leaves the same stop. Details are in #10051.

AI-assisted: yes. Written with AI assistance and reviewed by me.

@oneandonlydean oneandonlydean self-assigned this Oct 23, 2026
@oneandonlydean
oneandonlydean merged commit c383e37 into boykopovar:main Oct 23, 2026
11 checks passed
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.

4 participants