Skip to content

Keep CairoFont.FontMeasuringContext initialized - #727

Merged
Zaldaryon merged 1 commit into
mainfrom
fix/font-measuring-context-724
Nov 21, 2026
Merged

Zaldaryon merged 1 commit into
mainfrom
fix/font-measuring-context-724

Conversation

@Zaldaryon

Copy link
Copy Markdown
Collaborator

Fixes #724

Problem: since 0.4.0 the patched CairoFont static constructor is empty, so FontMeasuringContext stays null. A mod that locks it around GetTextExtents (Edge of Lineage Core does, in a Harmony prefix) throws ArgumentNullException and the world never loads.

Solution: the patcher no longer empties the constructor, and CairoFont.cs.patch keeps the surface field and constructor. The context is a managed recording surface, so libcairo stays unloaded unless OPTIMUM_CAIRO_NATIVE=allow.

Evidence: a Harmony prefix and finalizer that lock the field throws on the v0.4.4 stage and passes with this change. In a real client launch on Linux the game process maps libcoreclr and libSkiaSharp and no libcairo. CairoFontNativeFreeStartupTests now asserts the field is non-null and lockable (deny lane) and fails without the constructor.

Limit: the context is bound to its creating thread, so measuring text with it from another thread throws. Nothing in Optimum or the vanilla decompile reads it outside CairoFont. The mod itself was not run in the game.

ApiPatcherTextLayoutTests.FontLayoutPatchRewritesSerializedApiAndPreservesContextOverload also fails in the full Optimum.Tests run on unmodified v0.4.4 (it passes alone).

@Zaldaryon
Zaldaryon merged commit 5cfe9c8 into main Nov 21, 2026
45 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.

Keep CairoFont.FontMeasuringContext non-null for mods that lock it

1 participant