Repository: incubator-weex
Updated Branches:
  refs/heads/master e74c60cd3 -> 0cbbfba71


[WEEX-420][iOS] Try to resolve multithread crash during delete layoutNode

close #1227


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/0cbbfba7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/0cbbfba7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/0cbbfba7

Branch: refs/heads/master
Commit: 0cbbfba71932fd465c95adecf052c2ddd9691827
Parents: e74c60c
Author: zhongcang <qh438406...@gmail.com>
Authored: Wed May 30 20:58:44 2018 +0800
Committer: acton393 <zhangxing610...@gmail.com>
Committed: Thu May 31 16:39:13 2018 +0800

----------------------------------------------------------------------
 .../Sources/Component/WXScrollerComponent.mm       |  4 +---
 .../WeexSDK/Sources/Layout/WXComponent+Layout.h    |  3 +++
 .../WeexSDK/Sources/Layout/WXComponent+Layout.mm   | 17 +++++++++++++++++
 ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h      |  9 +++++++++
 ios/sdk/WeexSDK/Sources/Model/WXComponent.mm       |  5 +++--
 5 files changed, 33 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0cbbfba7/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm 
b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
index fcf554a..9b8a1a2 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Component/WXScrollerComponent.mm
@@ -247,9 +247,7 @@ WX_EXPORT_METHOD(@selector(resetLoadmore))
     [self.stickyArray removeAllObjects];
     [self.listenerArray removeAllObjects];
         if(_flexScrollerCSSNode){
-            delete _flexScrollerCSSNode;
-            
-            //WeexCore::WXCoreLayoutNode::freeNodeTree(_flexScrollerCSSNode);
+            [WXComponent recycleNodeOnComponentThread:_flexScrollerCSSNode 
gabRef:self.ref];
             
             _flexScrollerCSSNode=nullptr;
         }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0cbbfba7/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h 
b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h
index ac8700e..2f77976 100644
--- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h
+++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.h
@@ -59,4 +59,7 @@ extern "C" {
 - (void)_insertChildCssNode:(WXComponent*)subcomponent 
atIndex:(NSInteger)index;
 - (void)_rmChildCssNode:(WXComponent*)subcomponent;
 - (NSInteger) getActualNodeIndex:(WXComponent*)subcomponent 
atIndex:(NSInteger) index;
+#ifdef __cplusplus
++ (void) recycleNodeOnComponentThread:(WeexCore::WXCoreLayoutNode * ) 
garbageNode gabRef:(NSString *)ref;
+#endif
 @end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0cbbfba7/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm 
b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
index d1aa7d0..ecca959 100644
--- a/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
+++ b/ios/sdk/WeexSDK/Sources/Layout/WXComponent+Layout.mm
@@ -637,5 +637,22 @@ static WeexCore::WXCoreSize 
flexCssNodeMeasure(WeexCore::WXCoreLayoutNode *node,
 }
 
 
++ (void) recycleNodeOnComponentThread:(WeexCore::WXCoreLayoutNode * ) 
garbageNode gabRef:(NSString *)ref {
+    if (nullptr == garbageNode) {
+#ifdef DEBUG
+        WXLogDebug(@"flexlayout->recycle garbageNode ref:%@ is null ",ref);
+#endif
+        return;
+    }
+    WXPerformBlockOnComponentThread(^{
+#ifdef DEBUG
+        WXLogDebug(@"flexlayout->recycle  ref:%@ ,node:%p",ref,garbageNode );
+#endif
+        if(nullptr != garbageNode){
+            delete garbageNode;
+        }
+    });
+    //domthread
+}
 
 @end

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0cbbfba7/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h 
b/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h
index b7c299e..216c099 100644
--- a/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h
+++ b/ios/sdk/WeexSDK/Sources/Layout/WXCoreLayout.h
@@ -157,7 +157,16 @@ namespace WeexCore {
         mHasNewLayout = true;
         dirty = true;
         measureFunc = nullptr;
+        if(nullptr != mParent){
+            mParent->removeChild(this);
+        }
         mParent = nullptr;
+        for(WXCoreLayoutNode* childNode : mChildList){
+            if(nullptr != childNode){
+                childNode->mParent = nullptr;
+            }
+        }
+        
         mChildList.clear();
         BFCs.clear();
         NonBFCs.clear();

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0cbbfba7/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm 
b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
index 6cbbb25..f383ad8 100644
--- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
+++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm
@@ -222,11 +222,12 @@ static BOOL bNeedRemoveEvents = YES;
 
 - (void)dealloc
 {
-    if(self.flexCssNode){
+    if(_flexCssNode){
 #ifdef DEBUG
         WXLogDebug(@"flexLayout -> dealloc %@",self.ref);
 #endif
-        delete self.flexCssNode;
+        [WXComponent recycleNodeOnComponentThread:_flexCssNode gabRef:_ref];
+        _flexCssNode=nullptr;
     }
     
     // remove all gesture and all

Reply via email to