Bug in UIKit string drawing method?

后端 未结 3 1474
长情又很酷
长情又很酷 2020-12-19 14:46

In order to replicate a crash I was having in my application, I had to create a sample with a slightly exaggerated repeat rate that might not be practical, but one that demo

3条回答
  •  悲&欢浪女
    2020-12-19 15:05

    An easy workaround for this is to replace NSString with NSAttributedString.

    The crash test that @maq listed does not crash if modified like this:

    -(void)threadFunc:(UIFont *)font {
        @autoreleasepool {
            NSString *string = @" ";
            NSMutableAttributedString *test = [[NSMutableAttributedString alloc] initWithString:string];
            CGRect r = {{0,0},{50,50}};
            UIGraphicsBeginImageContextWithOptions(r.size, YES, 0);
            for(;;) {
                @autoreleasepool {
                     UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
                    [test addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, test.length)];
                    [test drawAtPoint:r.origin];
                }
            }
            UIGraphicsEndImageContext();
        }
    }
    

提交回复
热议问题