Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 9602c43

Browse files
wqyfavorjianhan-he
authored andcommitted
Fix text crash (#2442)
* [iOS] Fix crash that _view may be deallocated in other threads but still used while drawing text to temp context. The _view is unused at all! * [iOS] Fix crash that self is not properly used in block.
1 parent 6463f82 commit 9602c43

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,9 @@ - (UIImage *)drawRect:(CGRect)rect;
377377
{
378378
CGContextRef context = UIGraphicsGetCurrentContext();
379379
if (_isCompositingChild) {
380-
[self drawTextWithContext:context bounds:rect padding:_padding view:nil];
380+
[self drawTextWithContext:context bounds:rect padding:_padding];
381381
} else {
382-
WXTextView *textView = (WXTextView *)_view;
383-
[self drawTextWithContext:context bounds:rect padding:_padding view:textView];
382+
[self drawTextWithContext:context bounds:rect padding:_padding];
384383
}
385384

386385
return nil;
@@ -741,7 +740,7 @@ - (void)_updateAttributesOnComponentThread:(NSDictionary *)attributes
741740
[self syncTextStorageForView];
742741
}
743742

744-
- (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:(UIEdgeInsets)padding view:(WXTextView *)view
743+
- (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:(UIEdgeInsets)padding
745744
{
746745
if (bounds.size.width <= 0 || bounds.size.height <= 0) {
747746
return;

ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,26 @@ - (void)didFinishDrawingLayer:(BOOL)success
105105

106106
- (WXDisplayBlock)_displayBlock
107107
{
108+
__weak WXComponent* wself = self;
108109
WXDisplayBlock displayBlock = ^UIImage *(CGRect bounds, BOOL(^isCancelled)(void)) {
109110
if (isCancelled()) {
110111
return nil;
111112
}
112113

113-
UIGraphicsBeginImageContextWithOptions(bounds.size, [self _bitmapOpaqueWithSize:bounds.size] , 0.0);
114-
UIImage *image = [self drawRect:bounds];
115-
if (!image) {
116-
image = UIGraphicsGetImageFromCurrentImageContext();
114+
__strong WXComponent* sself = wself;
115+
if (sself) {
116+
UIGraphicsBeginImageContextWithOptions(bounds.size, [sself _bitmapOpaqueWithSize:bounds.size] , 0.0);
117+
UIImage *image = [sself drawRect:bounds];
118+
if (!image) {
119+
image = UIGraphicsGetImageFromCurrentImageContext();
120+
}
121+
UIGraphicsEndImageContext();
122+
123+
return image;
124+
}
125+
else {
126+
return nil;
117127
}
118-
UIGraphicsEndImageContext();
119-
120-
return image;
121128
};
122129

123130
return displayBlock;

0 commit comments

Comments
 (0)