All exception break point is stopping for no reason on simulator

ε祈祈猫儿з 提交于 2019-11-28 16:29:29

I was just experiencing the same exact problem and tracked down the issue.

Make sure that all fonts that you specify in your Info.plist under Fonts provided by this application are actually in your application bundle.

There's a more accurate way of tracking down the suspect font in your app using the debugger and the fact that it's conveniently stopped at the call.

Step 1: Reproduce the __cxa_throw breakpoint

Usually this happens when instantiating one of (or possibly the first) UIView object in your app. You'll see your debugger has broken and you'll have a stack such as this:

Step 2: Select the entry in the stack trace with the symbol FPFontCreateFontsWithPath

In my case, this entry was line 7 in the stack.

If you take a look at the disassembly, you'll notice the function signature of this entry:

Ah, cool! Looks like it takes some C strings. I betcha one of those is a filepath too!

Step 3: Locate that string in the app memory

I'm running this in a (x86_64) simulator, which on my computer stores the function arguments in some of the registers beginning with r. More details on registers here.

Either press Shift+Command+M or select the "Debug > Debug Workflow > View Memory" option from the menu.

At the bottom of this view, go through the registers one by one and enter the addresses. In my case, r14 contained the path of the file.

Alright, so now I know the font that's messed up. It's looking for HelveticaNeue.ttc. Let's find the reference to that in the project.

Open a terminal, navigate to your project and run:

$ ~/W/X/project> grep -R "HelveticaNeue" ./
.//MyProject/Main.Storyboard:        <array key="HelveticaNeue.ttc">
.//MyProject/Main.Storyboard:            <string>HelveticaNeue</string>
.//MyProject/Main.Storyboard:                                <fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="18"/>

Awesome, now either switch those to system by replacing name="HelveticaNeue" family="Helvetica Neue" with type="system", open the storyboard and manually edit them or add a reference to the missing font to your app (info.plist and target).

Step 4: Celebrate 🎉 🎊 🍾 🍻

As the backtrace shows, the app didn't stop for no reason. It stopped because an exception was thrown, and it looks like a C++ exception.

Unlike Objective-C, where exceptions should only be thrown as the result of programming errors and therefore are very rare, there is a lot of C++ code around that throws and catches lots of exceptions. In that situation, probably best to only set a breakpoint on Objective-C exceptions, not all exceptions.

If you didn't find a problem in .plist file maybe the problem is in your .storyboard file.. Open it as source code from Xcode or in textView from Finder - search for <customFonts key="customFonts"> I had there some old irrelevant array/font inside...:) just deleted it and it stopped

In my case the reference was inside xcuserdata :

user$ grep -R "HelveticaNeue" ./
Binary file .//MyProject.xcworkspace/xcuserdata/user.xcuserdatad/UserInterfaceState.xcuserstate matches

An exception is being thrown, but the caller (e.g. in libFontParser and libTrueTypeScaler) is handling it and it is not reaching your program.

Unless you see other evidence of a problem (such as a log message) or the exception reaches your program, assume that the implementation is handling it. You can continue past these instances in the debugger without worry.

I solved this issue by combining nmock's answer with DaNLtR's answer.

So at first i looked for <customFonts key="customFonts"> and there was Montserrat-Light present in it.
But it wasn't neither present in info.plist nor was it added to the project.

The problem vanished once i bundled Montserrat-Light.ttf into the project and added an entry for this font under Fonts provided by this application in info.plist.

So following is the summary of above mentioned solution:

  1. Look for your Storyboard or Xib files for any Custom Fonts.
    You'll find them in <customFonts key="customFonts">
  2. If there is Actually a Custom Font mentioned, then follow steps 3 and 4
  3. Add the font to your Xcode Project.
  4. Add an entry to info.plist under Fonts provided by this application.
    This entry should be name of the font file followed by its extension.
  5. In case if <customFonts key="customFonts"> doesn't contain any Custom Font (e.g: Helvetica-Neue etc), then try deleting the <customFonts key="customFonts"> entry in Stroyboard or Xib file as stated in DaNLtR's answer

I know its very late to answer but hope this helps someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!