Skip to content

Commit 4b3e0c1

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
docs: document precise root cause of AFontMatcher_match crash
AFontMatcher_match → minikin::SystemFonts::findFontCollection() → null mDefaultFallback → SIGSEGV in FontCollection::getFamilyForChar. The minikin singleton is populated by Java's Typeface static init: Typeface.<clinit> → loadPreinstalledSystemFontMap() → setSystemFontMap() → nativeAddFontCollections() [JNI] → minikin::SystemFonts::registerFallback() Without Java/ART, registerFallback is never called, so the singleton is empty. ASystemFontIterator works because it reads fonts.xml from the filesystem directly, bypassing minikin. Our fix (Go-side matching via ASystemFontIterator) is correct — there is no NDK API to populate minikin's singleton without Java.
1 parent 0c27ef9 commit 4b3e0c1

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

cmd/ndkcli/font_workflow.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,18 @@ import (
1111
)
1212

1313
// matchFontFromIterator iterates all system fonts and finds the best
14-
// match for the given family, weight, and italic style. This replaces
15-
// AFontMatcher_match which crashes from headless CLI binaries because
16-
// libminikin's FontCollection is not initialized without an app context.
14+
// match for the given family, weight, and italic style.
15+
//
16+
// This replaces AFontMatcher_match which crashes (SIGSEGV) from headless
17+
// CLI binaries. Root cause: AFontMatcher_match calls
18+
// minikin::SystemFonts::findFontCollection(), which accesses a singleton
19+
// populated by Java's Typeface static initializer via JNI
20+
// (nativeAddFontCollections → minikin::SystemFonts::registerFallback).
21+
// Without Java/ART running, the singleton's mDefaultFallback is null,
22+
// causing a null pointer dereference in FontCollection::getFamilyForChar.
23+
//
24+
// ASystemFontIterator works from CLI because it reads /system/etc/fonts.xml
25+
// directly from the filesystem, bypassing minikin's singleton entirely.
1726
func matchFontFromIterator(
1827
family string,
1928
weight uint16,

0 commit comments

Comments
 (0)