Open yuroyami opened 11 months ago
Confirmed that this happens only when I use a font variation that doesn't have regular variation. For example
MR.fonts.FooJay.bold.asFont()
. doesn't work if FooJay.regular doesn't exist...
But when I use a regular font like MR.fonts.FooBar.regular.asFont()
it works just fine... even if it is otf or ttf
I wonder if this is a iOS limitation or just a moko bug.
My solution was to rename my FooJay-Bold.otf
to FooJay-Regular.otf
Just curious, what is the crash you got ? I personally encounter a crash using a MyFont-Regular.ttf (using cocoa pods configuration snippet from the readme where copying the resources via a script when compiling)
In my case the crash is "Exception NSException * "*** -[NSMutableDictionary __addObject:forKey:]: object cannot be nil" 0x000000028396ef40"
and the font family is retrieved via fontFamilyResource(fontResource = Resources.fonts.MyFont.regular)
(if my issue is not related, I'll create a new ticket, will need to take some time to create a minimum reproduction project)
@codlab This is the same crash I got, exactly on Skia
's Paragraph.kt
. So there is no need to open a new ticket. I will rename the issue accordingly.
There is something that's leading the code to crash when using certain font variations for different fonts. For example, my Directive4 font is literally bold, but it doesn't work unless I define it as regular.
You could try renaming your font to MyFont-Bold.ttf
. You can also try having another copy of your MyFont-Regular.ttf
and rename it to MyFont-Bold.ttf
. I am thinking maybe it's all about the font family lacking certain variations or something. I am not an iOS dev expert so I wonder what the underlying system requires the fonts to be like. Anyway, the aforementioned workaround may may help the maintainers put their finger on the issue.
I don't think it's about the variations, in my case there is only the default variation. It must be about the variation(s) not properly loading. What I was thinking about is that the compilation passed because the generation tells that the value exist but then, at runtime, it crashes because the value can't be loaded properly and then the validation of type then tries to push a null value to a dictionary when it expected non null
it's definitely somewhere in between the resource lookup & loading it. Haven't successfully recompiled the lib for now tho
My apologies for the ambiguity, I am aware that your font is named based on its actual/default variation, which in my case corresponds to the Bold variation. However, renaming my font to Directive4-Regular.otf
worked although the font itself is bold.
It seems indeed to be an issue around loading the font at runtime. From what i understand about iOS frameworks, I wonder if migrating towards a static framework rather than a dynamic one would work, but I dislike the hassle of adding extra compile steps.
In my case the framework is built as static (hence the script as noted in the readme to copy the resources from it to the app) - even tried manually adding manually the font to the app as a resource
I use Compose multiplatform
1.5.1
(and 1.5.10-beta01). I get a crash when usingfontFamilyResource(MR.fonts.Directive4.bold)
on iOS (any device or version). It works fine on Android.How to reproduce : Create a normal Text composable with a custom FontFamily using moko-resources.
This also doesn't work:
MR.fonts.YOUR_FONT.asFont()
But it doesnt work. So yeah, I just can't use custom fonts in iOS. Maybe it works for 1.5.0 but I am not sure
EDIT: This happens because the font is bold, maybe because it doesn't have a regular variation ? See comment below.
NOTE: I only tested this with Text composables in Compose 1.5.1 and Material3
Here's the full crash report:
Full crash report
------------------------------------- Translated Report (Full Report Below) ------------------------------------- Incident Identifier: B5236F22-B07C-4E31-A023-F511C6F7034B CrashReporter Key: 378B04D7-3E25-65B4-D3DB-0DA5584BE7AF Hardware Model: MacBookAir7,2 Process: iosApp [12332] Path: /Users/USER/Library/Developer/CoreSimulator/Devices/E74CCD34-F064-40C4-AAEA-C5BC1DC0F8D7/data/Containers/Bundle/Application/C1422717-472B-40BA-A076-0C244CC6BAB8/iosApp.app/iosApp Identifier: com.yuroyami.syncplay Version: 1.0 (1) Code Type: X86-64 (Native) Role: Foreground Parent Process: launchd_sim [10521] Coalition: com.apple.CoreSimulator.SimDevice.E74CCD34-F064-40C4-AAEA-C5BC1DC0F8D7 [4719] Responsible Process: SimulatorTrampoline [788] Date/Time: 2023-09-18 20:38:02.9720 +0100 Launch Time: 2023-09-18 20:37:58.3888 +0100 OS Version: macOS 12.6.5 (21G531) Release Type: User Report Version: 104 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: UNKNOWN_0xD at 0x0000000000000000 Exception Codes: 0x000000000000000d, 0x0000000000000000 VM Region Info: 0 is not in any region. Bytes before following region: 4433260544 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL UNUSED SPACE AT START ---> __TEXT 1083e3000-1083e7000 [ 16K] r-x/r-x SM=COW ...pp.app/iosApp Exception Note: EXC_CORPSE_NOTIFY Termination Reason: SIGNAL 11 Segmentation fault: 11 Terminating Process: exc handler [12332] Triggered by Thread: 0 Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 shared 0x10f32f0e4 kfun:kotlin.collections.HashMap.hash#internal + 116 (HashMap.kt:218) 1 shared 0x10f330340 kfun:kotlin.collections.HashMap#addKey(1:0){}kotlin.Int + 464 (HashMap.kt:294) 2 shared 0x10f33943c kfun:kotlin.collections.HashSet#add(1:0){}kotlin.Boolean + 236 (HashSet.kt:37) 3 shared 0x10f2cb6ca kfun:kotlin.Throwable.ExceptionTraceBuilder.dumpSelfTrace#internal + 874 (Throwable.kt:94) 4 shared 0x10f2cb1fe kfun:kotlin.Throwable.ExceptionTraceBuilder.dumpFullTrace#internal + 430 (Throwable.kt:84) 5 shared 0x10f2caebb kfun:kotlin.Throwable.ExceptionTraceBuilder.print#internal + 203 (Throwable.kt:71) 6 shared 0x10f2caa1c kfun:kotlin.Throwable#printStackTrace(){} + 188 (Throwable.kt:55) 7 shared 0x10f2ffda2 ReportUnhandledException + 146 (RuntimeUtils.kt:153) 8 shared 0x110135039 (anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1::operator()() const + 9 9 shared 0x110134f0f void (anonymous namespace)::$_0::operator()<(anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1>((anonymous namespace)::terminateWithUnhandledException(ObjHeader*)::$_1) + 47 10 shared 0x110134d29 (anonymous namespace)::terminateWithUnhandledException(ObjHeader*) + 9 11 shared 0x110134ce7 (anonymous namespace)::processUnhandledException(ObjHeader*) + 55 12 shared 0x1101349fc (anonymous namespace)::TerminateHandler::kotlinHandler() + 204 13 libc++abi.dylib 0x7ff800257b65 std::__terminate(void (*)()) + 8 14 libc++abi.dylib 0x7ff80025a3a4 __cxa_rethrow + 99 15 libobjc.A.dylib 0x7ff80004dd0d objc_exception_rethrow + 37 16 CoreFoundation 0x7ff800381769 CFRunLoopRunSpecific + 754 17 GraphicsServices 0x7ff809cb128a GSEventRunModal + 139 18 UIKitCore 0x10c6d9ad3 -[UIApplication _run] + 994 19 UIKitCore 0x10c6de9ef UIApplicationMain + 123 20 SwiftUI 0x1097b3667 0x1086bf000 + 17778279 21 SwiftUI 0x1097b3514 0x1086bf000 + 17777940 22 SwiftUI 0x108e177e9 0x1086bf000 + 7702505 23 iosApp 0x1083e61ee static iOSApp.$main() + 30 (iOSApp.swift:4) 24 iosApp 0x1083e6299 main + 9 25 dyld_sim 0x1086292bf start_sim + 10 26 dyld 0x10b7e552e start + 462 Thread 1:: GC Timer thread 0 libsystem_kernel.dylib 0x7ff8361193da __psynch_cvwait + 10 1 libsystem_pthread.dylib 0x7ff836174a6f _pthread_cond_wait + 1249 2 libc++.1.dylib 0x7ff800290c73 std::__1::condition_variable::__do_timed_wait(std::__1::unique_lockstd::__1::mutex&, std::__1::chrono::time_pointFor testing purposes I attached the faulty font below. Just to put things into perspective: it crashes when it's named
Directive4-Bold.otf
, but works fine when it's namedDirective4-Regular.otf
Directive4-Regular.otf.zip