fix(libSceFreeType): preserve referenced face lifetimes #9437

Merged
Ondra97 merged 1 commit from upstream-pr/9437 into main 2026-10-25 18:35:23 +00:00
Ondra97 commented 2026-10-21 21:59:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-21T21:59:59Z.


What

A successful FT_Done_Face does not necessarily destroy the native face: it also returns zero when dropping a non-final reference. The guest bridge previously erased its owner on every zero result, invalidating the guest face and freeing file-backed font bytes while the native face was still alive.

Expose FT_Reference_Face and retain the guest owner until the existing native face finalizer has completed. Mark completion after the guest callback returns, so a nested non-final release inside that callback cannot erase its storage. Native FreeType remains responsible for the reference count; no second counter is introduced.

The name and NID HkSJXCHCQCU are present in the PS5 3.20 inventory. Reference and destruction behavior follow bundled FreeType 2.13.3. Console ABI, counter limits and finalizer behavior remain unverified and are recorded in debt.

The current open-PR scan found no independent implementation of FT_Reference_Face. #9419 shares a debt-file insertion and remains the documentation merge-order predecessor. #9550 repeats this PR's face-reference export and owner-lifetime hunk as an inherited implementation dependency, then adds separate size-object behavior; its checklist already depends on #9437. Merge #9419 first, then #9437, then #9550, retaining each distinct debt entry and size-object change during rebases.

Tested

Rebased on upstream main 941ace5f342c24c84b0712b8db0a75e0232bc44d; tested PR head 60a0f0f5e2ef9ee462718108dd3a27a8a1c495bd. Windows 11 Pro 10.0.26300, Ryzen 9 7900X, 31.7 GiB RAM, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Ninja, Release, BUILD_TESTING=ON, pinned bundled dependencies. The tests used the CPU.

  • cmake --build <build> --target libSceFreeType guest_freetype_tests guest_freetype_bitmap_tests guest_freetype_request_size_tests guest_freetype_outline_tests guest_freetype_outline_mutations_tests guest_freetype_charmap_tests guest_freetype_charmap_info_tests guest_freetype_face_info_tests guest_freetype_names_tests guest_freetype_sfnt_names_tests guest_freetype_list_tests guest_font_tests guest_system_font_tests guest_font_writing_line_tests font_face_lifetime_tests --parallel 10: the production FreeType library and focused fixtures built successfully without a source overlay.
  • ctest --test-dir <build> -R '^(guest_freetype.*|guest_.*font.*|font_.*)$' --output-on-failure --no-tests=error: 17/17 passed, zero skips. The face-reference regression compared 28 retains, 24 non-final releases and 8 finalized faces with native FreeType, including file-backed ownership and reentrant finalizers.
  • ctest --test-dir <build> -R '^public_headers($|_compile_)' -j 8 --output-on-failure --no-tests=error: 65/65 passed. The new FT_Reference_Face export has its sole public declaration in Api.hpp; the integrated test uses the public declaration and GuestLibrary* type. The production export body is unchanged from the old hosted PR.
  • python tools/check_test_registration.py <build>, python tools/check_conventions.py --base origin/main, python tools/check_main_sync.py --base origin/main --strict, and git diff origin/main...HEAD --check: passed. python tools/pr_overlap.py --branch codex/pr9437-rebase-20261025 --repo boykopovar/AnyPS5 --jobs 12 completed: #9419 is the declared debt-entry predecessor, #9550 inherits this face-reference change, and #10604/#10616 add different exports in adjacent code.

The previous PR head's main-baseline and early-finalizer negative controls remain historical evidence; they were not rerun on this head. The complete all-target build, patched-libraries loader, console probe and title run were not performed on this rebased head. Console ABI, reference-counter limits and finalizer behavior remain unverified as recorded in debt.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #9419 (documentation insertion order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4958941594 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9437). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-21T21:59:59Z. --- ### What A successful `FT_Done_Face` does not necessarily destroy the native face: it also returns zero when dropping a non-final reference. The guest bridge previously erased its owner on every zero result, invalidating the guest face and freeing file-backed font bytes while the native face was still alive. Expose `FT_Reference_Face` and retain the guest owner until the existing native face finalizer has completed. Mark completion after the guest callback returns, so a nested non-final release inside that callback cannot erase its storage. Native FreeType remains responsible for the reference count; no second counter is introduced. The name and NID `HkSJXCHCQCU` are present in the [PS5 3.20 inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceFreeTypeOt.c). Reference and destruction behavior follow [bundled FreeType 2.13.3](https://github.com/freetype/freetype/blob/42608f77f20749dd6ddc9e0536788eaad70ea4b5/src/base/ftobjs.c#L2924). Console ABI, counter limits and finalizer behavior remain unverified and are recorded in debt. The current open-PR scan found no independent implementation of `FT_Reference_Face`. #9419 shares a debt-file insertion and remains the documentation merge-order predecessor. #9550 repeats this PR's face-reference export and owner-lifetime hunk as an inherited implementation dependency, then adds separate size-object behavior; its checklist already depends on #9437. Merge #9419 first, then #9437, then #9550, retaining each distinct debt entry and size-object change during rebases. ### Tested Rebased on upstream `main` `941ace5f342c24c84b0712b8db0a75e0232bc44d`; tested PR head `60a0f0f5e2ef9ee462718108dd3a27a8a1c495bd`. Windows 11 Pro 10.0.26300, Ryzen 9 7900X, 31.7 GiB RAM, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Ninja, Release, `BUILD_TESTING=ON`, pinned bundled dependencies. The tests used the CPU. - `cmake --build <build> --target libSceFreeType guest_freetype_tests guest_freetype_bitmap_tests guest_freetype_request_size_tests guest_freetype_outline_tests guest_freetype_outline_mutations_tests guest_freetype_charmap_tests guest_freetype_charmap_info_tests guest_freetype_face_info_tests guest_freetype_names_tests guest_freetype_sfnt_names_tests guest_freetype_list_tests guest_font_tests guest_system_font_tests guest_font_writing_line_tests font_face_lifetime_tests --parallel 10`: the production FreeType library and focused fixtures built successfully without a source overlay. - `ctest --test-dir <build> -R '^(guest_freetype.*|guest_.*font.*|font_.*)$' --output-on-failure --no-tests=error`: 17/17 passed, zero skips. The face-reference regression compared 28 retains, 24 non-final releases and 8 finalized faces with native FreeType, including file-backed ownership and reentrant finalizers. - `ctest --test-dir <build> -R '^public_headers($|_compile_)' -j 8 --output-on-failure --no-tests=error`: 65/65 passed. The new `FT_Reference_Face` export has its sole public declaration in `Api.hpp`; the integrated test uses the public declaration and `GuestLibrary*` type. The production export body is unchanged from the old hosted PR. - `python tools/check_test_registration.py <build>`, `python tools/check_conventions.py --base origin/main`, `python tools/check_main_sync.py --base origin/main --strict`, and `git diff origin/main...HEAD --check`: passed. `python tools/pr_overlap.py --branch codex/pr9437-rebase-20261025 --repo boykopovar/AnyPS5 --jobs 12` completed: #9419 is the declared debt-entry predecessor, #9550 inherits this face-reference change, and #10604/#10616 add different exports in adjacent code. The previous PR head's main-baseline and early-finalizer negative controls remain historical evidence; they were not rerun on this head. The complete all-target build, patched-libraries loader, console probe and title run were not performed on this rebased head. Console ABI, reference-counter limits and finalizer behavior remain unverified as recorded in debt. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> #9419 (documentation insertion order only) - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
Ondra97 commented 2026-10-22 01:56:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-22T01:56:18Z.


I opened #9550 to add FT_New_Size, FT_Activate_Size and FT_Done_Size. I declared #9437 as the implementation dependency: guest size records must survive non-final face releases and all native size finalizers. Merge this face-lifetime fix first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330814751 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9437#issuecomment-6330814751). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-22T01:56:18Z. --- I opened #9550 to add FT_New_Size, FT_Activate_Size and FT_Done_Size. I declared #9437 as the implementation dependency: guest size records must survive non-final face releases and all native size finalizers. Merge this face-lifetime fix first.
MarcZX10 commented 2026-10-22 04:41:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:41:12Z.

Review: DISMISSED


The owner now remains registered until the native finalizer has returned, so a successful non-final FT_Done_Face no longer drops its guest wrapper or file-backed font bytes. I reviewed the reentrant-finalizer case and the native-vs-guest reference-depth coverage; the reported Windows full integration build and 9/9 focused CTests are strong, including the documented temporary #8310 compiler workaround. The required technical-debt entry also states that console ABI/refcount/finalizer behavior remains unverified.

The final tested head is based on a6dcea927, while current upstream main is 17f5335562. Please update and rerun the FreeType lifecycle suite, conventions and overlap checks on current main. Preserve the stated docs order with #9419; the new size PR #9550 already correctly depends on this lifetime fix. I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609344730 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9437#pullrequestreview-5609344730). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:41:12Z. **Review:** DISMISSED --- The owner now remains registered until the native finalizer has returned, so a successful non-final `FT_Done_Face` no longer drops its guest wrapper or file-backed font bytes. I reviewed the reentrant-finalizer case and the native-vs-guest reference-depth coverage; the reported Windows full integration build and 9/9 focused CTests are strong, including the documented temporary #8310 compiler workaround. The required technical-debt entry also states that console ABI/refcount/finalizer behavior remains unverified. The final tested head is based on `a6dcea927`, while current upstream main is `17f5335562`. Please update and rerun the FreeType lifecycle suite, conventions and overlap checks on current main. Preserve the stated docs order with #9419; the new size PR #9550 already correctly depends on this lifetime fix. I did not run local tests.
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!9437
No description provided.