Core Graphics Crash

  • 0 CoreGraphics 0x00000001bd87ddc0 _CGSColorMaskCopyARGB8888_arm + 656
  • 1 CoreGraphics 0x00000001bd883920 _RIPLayerBltGlyph + 4224
  • 2 CoreGraphics 0x00000001bd8592e0 _render_glyph_list + 380
  • 3 CoreGraphics 0x00000001bd859510 _render_glyphs + 332
  • 4 CoreGraphics 0x00000001bd8590b0 _draw_glyph_bitmaps + 1124
  • 5 CoreGraphics 0x00000001bd858450 _ripc_DrawGlyphs + 1160
  • 6 CoreGraphics 0x00000001bd733db0 CGContextDelegateDrawGlyphs + 28
  • 7 CoreGraphics 0x00000001bd88d160 _draw_glyphs + 608
  • 8 CoreText 0x00000001bf78d640 DrawGlyphsAtPositions(TFont const*, unsigned short const*, CGPoint const*, unsigned long, CGContext*, CGAffineTransform, CGAffineTransform, bool) + 2836
  • 9 CoreText 0x00000001bf78a4f0 DrawGlyphsWithAdvancesAndTransform(TFont const*, unsigned short const*, CGSize const*, unsigned long, CGPoint, CGContext*, CGAffineTransform, CGAffineTransform, bool) + 344
  • 10 CoreText 0x00000001bf78b880 _CTFontDrawGlyphsWithAdvancesInternal + 448
  • 11 CoreText 0x00000001bf758620 TRun::DrawGlyphs(CGContext*, CFRange) const + 552
  • 12 CoreText 0x00000001bf76f760 TLine::DrawGlyphs(CGContext*) const + 192
  • 13 UIFoundation 0x00000001c629c400 -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:context:forceClipping:styledTextOptions:attributes:stringDrawingOptions:drawingContext:wantsTextLineFragments:validatedAttributedString:firstNonRenderedCharacterIndex:foundSoftHyphenAtEOL:enginePathUsed:] + 9996
  • 14 UIFoundation 0x00000001c631ac10 ___NSStringDrawingEngine + 3096
  • 15 UIFoundation 0x00000001c62a6850 -[NSAttributedString(NSExtendedStringDrawing) drawWithRect:options:context:] + 504
  • 16 UIKitCore 0x00000001e9ae4eb0 0x00000001e8d89000 + 14007984
  • 17 UIKitCore 0x00000001e9ae3780 0x00000001e8d89000 + 14002048
  • 18 UIKitCore 0x00000001e9b78700 0x00000001e8d89000 + 14612224
  • 19 QuartzCore 0x00000001c0098ca0 -[CALayer drawInContext:] + 292

Replies

Please, note that just posting a crash report is not the right thing to do. In addition, it is not very respectful to readers to dump a raw crash report without any information.


So, please:

- explain the context

- remind the XCode and iOS version

- post the code where the crash occurs

- precise the exact line of crash.

Sorry man, I forgot the details


1. Context

I'm trying to render a UILabel's layer using - (void)drawInContext:(CGContextRef)ctx;

and the properties of the label (such as textColor、attributedText) may be changed under some circumstances.


2. Environments

Xcode 10.2.1

iOS 12.1.2


3. Simplified Code


    UILabel *someLabel = [[UILabel alloc] init];
    // setting attributes
    someLabel.text = @"hello, world";
    CGSize size = CGSizeMake(50, 20);
    someLabel.frame = CGRectMake(0, 0, size.width, size.height);
    someLabel.textColor = [UIColor whiteColor]; // textColor may be modified in other scenarios
    someLabel.attributedText = ....             // attributedText may be modified in other scenarios

    UIGraphicsBeginImageContextWithOptions(size, 0, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [someLabel.layer drawInContext:context]; // crashed here
    UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

I'm not very fluent with objc, but:


Try with a Float scale.


callling:


CGFloat scale = 0.0;
UIGraphicsBeginImageContextWithOptions(size, NO, scale);