开发者

Advice on Debugging a UIAppFonts Issue on iPad

开发者 https://www.devze.com 2023-01-18 15:42 出处:网络
I recently found this post which seems to describe the same problem I am having with adding my own ttf.My app freezes.However, a few things about the post confuse me, and I\'d love to get some help de

I recently found this post which seems to describe the same problem I am having with adding my own ttf. My app freezes. However, a few things about the post confuse me, and I'd love to get some help deciphering it.

The post is here: http://web.archiveorange.com/archive/v/nagQXB5eX3YsQpevIXMk

The relevant passages that I'm trying to understand are below:

Attaching the debugger and pausing the application reveals a not especially helpful call stack:

0 0xffff028f in __spin_lock

1 ??

Specific code that is causing the problem:

CTFontCollectionRef collection = CTFontCollectionCreateFromAvailableFonts(NULL); CFArrayRef fonts = CTFontCollectionCreateMatchingFontDescriptors(collection); for(id fontDescRef in (NSArray *)fonts) { CFStringRef fontName = CTFontDescriptorCopyAttribute((CTFontDescriptorRef)fontDescRef, kCTFontNameAttribute); NSLog(@"%@", fontName); CFRelease(fontName); }

CFRelease(fonts);

Execution never moves beyond the second line.

Question: How did he figure out what line and function was causing the problem? Was this something having to do with displaying the disassembly, showing it in mixed mode, or looking up a hex value in a map file? I'd like to learn how this was done.

Having been asked to supply a demo and hence having investigated further, I've found that the problem manifests if the code is in my application:didFinishLaunchingWithOptions: but not if I have the same stuff in the viewDidLoad of my initial view controller.

Question: what is 'the code' he's referring to here? The p开发者_如何学Croblem had to do with adding custom fonts through a plist value, so I'm not sure what he could be referring to or how I can workaround my issue.

Please Help!


Well, nothing on figuring out this post, but I did find a workaround posted by someone on the apple dev forums. Basically, calling this from the applicationDidFinishLaunching fn:

- (NSUInteger) loadFonts {
     NSUInteger newFontCount = 0;
     NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:@"com.apple.GraphicsServices"];
     const char *frameworkPath = [[frameworkBundle executablePath] UTF8String];
     if (frameworkPath) {
          void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
          if (graphicsServices) {
               BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, "GSFontAddFromFile");
               if (GSFontAddFromFile)
                    for (NSString *fontFile in [[NSBundle mainBundle] pathsForResourcesOfType:@"ttf" inDirectory:nil])
                         newFontCount += GSFontAddFromFile([fontFile UTF8String]);
          }
     }

     return newFontCount;
}

and making sure to include dlcfn.h and to cast the result of dlsym to the following:

(BOOL()(const char))

I did not alter the original post just in case this error was just something that affected me.

0

精彩评论

暂无评论...
验证码 换一张
取 消