From d32a731cac4b40c3fcef4c706ffd8bbfba1c0c8c Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 21 Aug 2017 22:27:59 +0800 Subject: [PATCH 1/2] Fix network binding issues --- .../scripting/js-bindings/manual/network/XMLHTTPRequest.cpp | 3 +-- .../scripting/js-bindings/manual/network/jsb_websocket.cpp | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp b/native/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp index 50c9544896..c7189eb8b7 100644 --- a/native/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp +++ b/native/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp @@ -397,8 +397,6 @@ JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest) JS::RootedObject proto(cx, MinXmlHttpRequest::js_proto); JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, MinXmlHttpRequest::js_class, proto)); - js_add_FinalizeHook(cx, obj, false); - jsb_new_proxy(cx, req, obj); #if CC_ENABLE_GC_FOR_NATIVE_OBJECTS js_add_FinalizeHook(cx, obj, true); @@ -411,6 +409,7 @@ JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest) req->autorelease(); // JS::AddNamedObjectRoot(cx, &p->obj, "XMLHttpRequest"); #endif + jsb_new_proxy(cx, req, obj); JS::RootedValue out(cx); if (obj) diff --git a/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp b/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp index 0f47a7b343..a07f7561af 100644 --- a/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp +++ b/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp @@ -175,6 +175,7 @@ public: auto copy = &p->obj; JS::RemoveObjectRoot(cx, copy); #endif + JS_SetPrivate(p->obj, nullptr); jsb_remove_proxy(p); } } From 67f08532ce51deb31df74c31f35c98b821dbd24c Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 21 Aug 2017 22:46:34 +0800 Subject: [PATCH 2/2] Fix closing app crash in websocket finalize --- .../js-bindings/manual/network/jsb_websocket.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp b/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp index a2ee031db0..032225fd69 100644 --- a/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp +++ b/native/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp @@ -214,11 +214,14 @@ void js_cocos2dx_WebSocket_finalize(JSFreeOp *fop, JSObject *obj) { if (cobj) { js_proxy_t * p = jsb_get_native_proxy(cobj); + if (p) + { #if not CC_ENABLE_GC_FOR_NATIVE_OBJECTS - auto copy = &p->obj; - JS::RemoveObjectRoot(cx, copy); + auto copy = &p->obj; + JS::RemoveObjectRoot(cx, copy); #endif - jsb_remove_proxy(p); + jsb_remove_proxy(p); + } ScriptingCore::getInstance()->setFinalizing(true); // Manually close if WebSocket is not closed