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

Merged
klosixgaming-arch merged 1 commit from upstream-pr/9992 into main 2026-10-23 12:58:09 +00:00
klosixgaming-arch commented 2026-10-23 03:19:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-23T03:19:51Z.


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.

#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 #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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4977304532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9992). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-23T03:19:51Z. --- ### 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 - [x] Based on current `main`; open PR #8250 touches the same validation for a different case (see above) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: nothing yet (Tekken Dark Resurrection still stops later, see above) - [x] AI-assisted: yes AI-assisted: yes. Written with AI assistance and reviewed by me. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01QLz9JYSXCPssYHgRW1CxJH
MarcZX10 commented 2026-10-23 03:22:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T03:22:15Z.

Review: APPROVED


Reviewed exact head c0024158db 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623518244 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9992#pullrequestreview-5623518244). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T03:22:15Z. **Review:** APPROVED --- Reviewed exact head c0024158db26ef721643a3f76947480a118c1ac2 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9992
No description provided.