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

Commit

Permalink
Fix text crash (#2442)
Browse files Browse the repository at this point in the history
* [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.
  • Loading branch information
wqyfavor authored and jianhan-he committed May 16, 2019
1 parent 6463f82 commit 9602c43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
7 changes: 3 additions & 4 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,9 @@ - (UIImage *)drawRect:(CGRect)rect;
{
CGContextRef context = UIGraphicsGetCurrentContext();
if (_isCompositingChild) {
[self drawTextWithContext:context bounds:rect padding:_padding view:nil];
[self drawTextWithContext:context bounds:rect padding:_padding];
} else {
WXTextView *textView = (WXTextView *)_view;
[self drawTextWithContext:context bounds:rect padding:_padding view:textView];
[self drawTextWithContext:context bounds:rect padding:_padding];
}

return nil;
Expand Down Expand Up @@ -741,7 +740,7 @@ - (void)_updateAttributesOnComponentThread:(NSDictionary *)attributes
[self syncTextStorageForView];
}

- (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:(UIEdgeInsets)padding view:(WXTextView *)view
- (void)drawTextWithContext:(CGContextRef)context bounds:(CGRect)bounds padding:(UIEdgeInsets)padding
{
if (bounds.size.width <= 0 || bounds.size.height <= 0) {
return;
Expand Down
21 changes: 14 additions & 7 deletions ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,26 @@ - (void)didFinishDrawingLayer:(BOOL)success

- (WXDisplayBlock)_displayBlock
{
__weak WXComponent* wself = self;
WXDisplayBlock displayBlock = ^UIImage *(CGRect bounds, BOOL(^isCancelled)(void)) {
if (isCancelled()) {
return nil;
}

UIGraphicsBeginImageContextWithOptions(bounds.size, [self _bitmapOpaqueWithSize:bounds.size] , 0.0);
UIImage *image = [self drawRect:bounds];
if (!image) {
image = UIGraphicsGetImageFromCurrentImageContext();
__strong WXComponent* sself = wself;
if (sself) {
UIGraphicsBeginImageContextWithOptions(bounds.size, [sself _bitmapOpaqueWithSize:bounds.size] , 0.0);
UIImage *image = [sself drawRect:bounds];
if (!image) {
image = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();

return image;
}
else {
return nil;
}
UIGraphicsEndImageContext();

return image;
};

return displayBlock;
Expand Down

0 comments on commit 9602c43

Please sign in to comment.