ibireme / YYText

Powerful text framework for iOS to display and edit rich text.
MIT License
8.84k stars 1.68k forks source link

YYTextAsyncLayer 我遇到了 BUG #950

Open iamlion opened 3 years ago

iamlion commented 3 years ago

Thread 0 Crashed: 0 libobjc.A.dylib 0x00000001b576c020 0x1b5747000 + 151584 1 移动基座 - [YYTextAsyncLayer _displayAsync:] (in ) (KKYYTextAsyncLayer.m:225) 2 移动基座 -[YYTextAsyncLayer display] (in ) (KKYYTextAsyncLayer.m:115) 3 QuartzCore 0x00000001a3b63420 0x1a39ef000 + 1524768 4 QuartzCore 0x00000001a3aa8640 0x1a39ef000 + 759360 5 QuartzCore 0x00000001a3ad3b08 0x1a39ef000 + 936712 6 QuartzCore 0x00000001a3ad4e98 0x1a39ef000 + 941720 7 CoreFoundation 0x00000001a06ac358 0x1a060c000 + 656216 8 CoreFoundation 0x00000001a06a65c4 0x1a060c000 + 632260 9 CoreFoundation 0x00000001a06a6b74 0x1a060c000 + 633716 10 CoreFoundation 0x00000001a06a621c 0x1a060c000 + 631324 11 GraphicsServices 0x00000001b8273784 0x1b8270000 + 14212 12 UIKitCore 0x00000001a30e6ee8 0x1a251e000 + 12357352 13 UIKitCore 0x00000001a30ec75c 0x1a251e000 + 12379996 14 移动基座 main (in ) (main.m:13) 0x1046b0000 + 210220 15 libdyld.dylib 0x00000001a03666b0 0x1a0365000 + 5808

iamlion commented 3 years ago

偶发性的,但是频率也很高,iOS14 以上会出现,

iamlion commented 3 years ago

UIGraphicsEndImageContext() 定位到这行代码出的错,野指针闪退

iamlion commented 3 years ago

在一些复杂场景下,context 被释放了,如同调用 CGConextRelease(),这时候调用 UIGraphicsEndImageContext() 产生闪退,目前我加了点防护后,情况好转了。

               void *data = CGBitmapContextGetData(context);
                if(data != NULL){
                    if (task && task.display) task.display(context, self.bounds.size, ^{return NO;});
                    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
                    UIGraphicsEndImageContext();
                    self.contents = (__bridge id)(image.CGImage);
                    if (task.didDisplay) task.didDisplay(self, YES);
                }