LiveUI / Awesome

FontAwesome 6 Swift & SwiftUI implementation for iOS, tvOS & macOS
MIT License
97 stars 27 forks source link

`AwesomePro.loadFonts` should throw/check for already registered ....? #40

Closed syky27 closed 5 years ago

syky27 commented 5 years ago

Hi,

I have quick question/suggestion it be throwing since there can be exception here: https://github.com/LiveUI/Awesome/blob/master/Classes/Libs/Fonts.swift#L138

I am getting this:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The operation couldn’t be completed. (com.apple.CoreText.CTFontManagerErrorDomain error 105 - Could not register the CGFont '<CGFont (0x600002fa4a00): FontAwesome5BrandsRegular>')'

Thanks

syky27 commented 5 years ago

Anyway I dont think that is my porblem actually I removed all that could potentionaly throw, and xcode seems to have problem with locating the exception origin...

2019-03-01 18:50:54.468735+0100 OPTIFY[79702:7776458] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The operation couldn’t be completed. (com.apple.CoreText.CTFontManagerErrorDomain error 105 - Could not register the CGFont '<CGFont (0x600001d54380): FontAwesome5BrandsRegular>')'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001078841bb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x00000001066fb735 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000107883d29 -[NSException raise] + 9
    3   AwesomeEnum                         0x00000001013f6a4f $S11AwesomeEnum5FontsC4load4type4fromyAA0A4Font_p_So8NSBundleCSgtFZ + 5375
    4   AwesomeEnum                         0x00000001013f51b3 $S11AwesomeEnum0A3ProV9loadFonts4from4onlyySo8NSBundleC_SayAC4FontOGtFZ + 1155
    5   OPTIFY                              0x000000010010ed27 $S6OPTIFY8MenuViewCACycfc + 951
    6   OPTIFY                              0x000000010010ef33 $S6OPTIFY8MenuViewCACycfcTo + 19
    7   OPTIFY                              0x000000010010e90c $S6OPTIFY8MenuViewCACycfC + 44
    8   OPTIFY                              0x00000001000f5fab $S6OPTIFY20MasterViewControllerCACyc33_119A8148CDB5D772F9F7B8DBD70A7DB7Llfc + 123
    9   OPTIFY                              0x00000001000f6fb3 $S6OPTIFY20MasterViewControllerCACyc33_119A8148CDB5D772F9F7B8DBD70A7DB7LlfcTo + 19
    10  OPTIFY                              0x00000001000f5b2c $S6OPTIFY20MasterViewControllerCACyc33_119A8148CDB5D772F9F7B8DBD70A7DB7LlfC + 44
    11  OPTIFY                              0x00000001000f7076 $S6OPTIFY20MasterViewControllerC5resetyyF + 182
    12  OPTIFY                              0x00000001001f1b31 $S6OPTIFY19LoginViewControllerC13redirectToApp33_50830A53D9EF86B5152B0F261BCAA132LLyyF + 1265
    13  OPTIFY                              0x00000001001f3986 $S6OPTIFY19LoginViewControllerC5loginyyFyAA11ResultStateOcfU_y0F0AGOyytAA8APIErrorVGcfU_ + 1270
    14  OPTIFY                              0x00000001001f4aad $S6OPTIFY19LoginViewControllerC5loginyyFyAA11ResultStateOcfU_y0F0AGOyytAA8APIErrorVGcfU_TA + 13
    15  OPTIFY                              0x00000001001f3a34 $S6ResultAAOyyt6OPTIFY8APIErrorVGIegg_AFIegn_TR + 52
    16  OPTIFY                              0x00000001001f4b01 $S6ResultAAOyyt6OPTIFY8APIErrorVGIegg_AFIegn_TRTA + 17
    17  ReactiveSwift                       0x00000001036776a2 $S13ReactiveSwift14SignalProducerV15startWithResultyAA10Disposable_py0G0AFOyxq_GcFyxcfU_ + 210
    18  ReactiveSwift                       0x000000010369f684 $S13ReactiveSwift14SignalProducerV15startWithResultyAA10Disposable_py0G0AFOyxq_GcFyxcfU_TA + 52
    19  ReactiveSwift                       0x000000010362f5e8 $S13ReactiveSwift6SignalC8ObserverC5value6failed9completed11interruptedAEyxq__GyxcSg_yq_cSgyycSgAMtcfcyAC5EventOyxq__GcfU_ + 712
    20  ReactiveSwift                       0x000000010362f99e $S13ReactiveSwift6SignalC8ObserverC5value6failed9completed11interruptedAEyxq__GyxcSg_yq_cSgyycSgAMtcfcyAC5EventOyxq__GcfU_TA + 110
    21  ReactiveSwift                       0x000000010362fcb4 $S13ReactiveSwift6SignalC8ObserverC4sendyyAC5EventOyxq__GF + 100
    22  ReactiveSwift                       0x000000010367520b $S13ReactiveSwift15TransformerCore33_8C2AEE826CBF26B7535B1491D314A4F4LLC5startyAA10Disposable_pAA6SignalC8ObserverCyxq__GAaF_pXEFAJyq0_q1__GAaF_pXEfU_yAH5EventOyxq__GcfU_ + 443
    23  ReactiveSwift                       0x000000010369ee76 $S13ReactiveSwift15TransformerCore33_8C2AEE826CBF26B7535B1491D314A4F4LLC5startyAA10Disposable_pAA6SignalC8ObserverCyxq__GAaF_pXEFAJyq0_q1__GAaF_pXEfU_yAH5EventOyxq__GcfU_TA + 70
    24  ReactiveSwift                       0x0000000103604c65 $S13ReactiveSwift6SignalC5EventO7observe2onyAEyxq__GcyAHc_AA8LifetimeCtcAA9Scheduler_p_tFZyAHcyAHc_AJtcfU_yAHcfU0_yycfU_ + 149
    25  ReactiveSwift                       0x0000000103611ffa $S13ReactiveSwift6SignalC5EventO7observe2onyAEyxq__GcyAHc_AA8LifetimeCtcAA9Scheduler_p_tFZyAHcyAHc_AJtcfU_yAHcfU0_yycfU_TA + 74
    26  ReactiveSwift                       0x00000001036468c2 $S13ReactiveSwift11UISchedulerC8scheduleyAA10Disposable_pSgyycFyycfU_ + 98
    27  ReactiveSwift                       0x0000000103646959 $S13ReactiveSwift11UISchedulerC8scheduleyAA10Disposable_pSgyycFyycfU_TA + 25
    28  ReactiveSwift                       0x00000001036469bd $SIeg_IeyB_TR + 45
    29  libdispatch.dylib                   0x0000000109114595 _dispatch_call_block_and_release + 12
    30  libdispatch.dylib                   0x0000000109115602 _dispatch_client_callout + 8
    31  libdispatch.dylib                   0x000000010912299a _dispatch_main_queue_callback_4CF + 1541
    32  CoreFoundation                      0x00000001077e93e9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    33  CoreFoundation                      0x00000001077e3a76 __CFRunLoopRun + 2342
    34  CoreFoundation                      0x00000001077e2e11 CFRunLoopRunSpecific + 625
    35  GraphicsServices                    0x000000010b0791dd GSEventRunModal + 62
    36  UIKitCore                           0x000000011114c81d UIApplicationMain + 140
    37  OPTIFY                              0x00000001002050a7 main + 71
    38  libdyld.dylib                       0x000000010918b575 start + 1
    39  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
syky27 commented 5 years ago

I am quite sure that this is caused by registering the font more than once...

I would like to somehow check if the font is already registered, but I cannot find it in documentation by Apple, it seem to be rather vague... :(

EDIT: everything I said migt be just wrong, this is what I get when I delete the suspected part from Font.swift

screenshot 2019-03-01 19 01 43

Not quite sure what to do here, I know that I can solve my problem differently but I wanted to let you know to make this lib even better...

ghowen commented 5 years ago

This has been fixed with https://github.com/LiveUI/Awesome/pull/39 and should be available shortly.

We do check if the font has been loaded, but FontAwesome renamed their fonts with version 5.7. As we have the font names hardcoded in the library, we needed to update.

Just waiting for someone to accept the PR and publish the pod.

syky27 commented 5 years ago

@ghowen I would love to get back to it and test this as I dont think this will fix it because I am running old version of Awesome with old version of AwesomePro fonts (did not have time to update) and I did not touch it for very long time...

ghowen commented 5 years ago

With the latest release 2.1.0 you must have FA fonts 5.7 or greater installed, otherwise the app will crash (again). Same if you have version 2.0.x of this library and FA fonts 5.7. So you need to have both in sync. The free fonts are part of the library and automatically updated but it's your obligation to keep the pro fonts in sync.

syky27 commented 5 years ago

ack

ghowen commented 5 years ago

2.1.0 was just released in Cocoapods. This should fix the issue. Make sure to clean your build folder after updating the pods as otherwise your app might still crash.