You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ji...@apache.org on 2019/05/16 02:17:38 UTC

[incubator-weex] branch master updated: Fix text crash (#2442)

This is an automated email from the ASF dual-hosted git repository.

jianhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-weex.git


The following commit(s) were added to refs/heads/master by this push:
     new 9602c43  Fix text crash (#2442)
9602c43 is described below

commit 9602c430f282e596bb1e40861c46b77980d6a9ee
Author: wqyfavor <qi...@taobao.com>
AuthorDate: Thu May 16 10:17:34 2019 +0800

    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.
---
 .../WeexSDK/Sources/Component/WXTextComponent.mm    |  7 +++----
 .../WeexSDK/Sources/Display/WXComponent+Display.m   | 21 ++++++++++++++-------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
index 9f25e56..61babea 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
@@ -377,10 +377,9 @@ do {\
 {
     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;
@@ -741,7 +740,7 @@ do {\
     [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;
diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
index 4982dde..78ae8c2 100644
--- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
+++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
@@ -105,19 +105,26 @@ typedef NS_ENUM(NSInteger, WXComponentBorderRecord) {
 
 - (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;