From 40731fbcbb391edf2de53fcf41bf1871c5de8f16 Mon Sep 17 00:00:00 2001 From: leda Date: Wed, 31 Oct 2018 15:12:12 +0800 Subject: [PATCH] free global g_textInputCallback before ScriptEngine clean up (#1576) --- native/cocos/ui/edit-box/EditBox-android.cpp | 4 ++++ native/cocos/ui/edit-box/EditBox-ios.mm | 4 ++++ native/cocos/ui/edit-box/EditBox-mac.mm | 4 ++++ native/cocos/ui/edit-box/EditBox-win32.cpp | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/native/cocos/ui/edit-box/EditBox-android.cpp b/native/cocos/ui/edit-box/EditBox-android.cpp index 69200fc203..0abdccecd9 100644 --- a/native/cocos/ui/edit-box/EditBox-android.cpp +++ b/native/cocos/ui/edit-box/EditBox-android.cpp @@ -72,6 +72,10 @@ namespace if (global->getProperty("jsb", &jsbVal) && jsbVal.isObject()) { jsbVal.toObject()->getProperty("onTextInput", &textInputCallback); + // free globle se::Value before ScriptEngine clean up + se::ScriptEngine::getInstance()->addBeforeCleanupHook([](){ + textInputCallback.setUndefined(); + }); } } diff --git a/native/cocos/ui/edit-box/EditBox-ios.mm b/native/cocos/ui/edit-box/EditBox-ios.mm index b8c0f71748..f564f284f2 100644 --- a/native/cocos/ui/edit-box/EditBox-ios.mm +++ b/native/cocos/ui/edit-box/EditBox-ios.mm @@ -126,6 +126,10 @@ namespace if (global->getProperty("jsb", &jsbVal) && jsbVal.isObject()) { jsbVal.toObject()->getProperty("onTextInput", &textInputCallback); + // free globle se::Value before ScriptEngine clean up + se::ScriptEngine::getInstance()->addBeforeCleanupHook([](){ + textInputCallback.setUndefined(); + }); } } diff --git a/native/cocos/ui/edit-box/EditBox-mac.mm b/native/cocos/ui/edit-box/EditBox-mac.mm index ec337d4647..fc6ae57398 100644 --- a/native/cocos/ui/edit-box/EditBox-mac.mm +++ b/native/cocos/ui/edit-box/EditBox-mac.mm @@ -162,6 +162,10 @@ namespace if (global->getProperty("jsb", &jsbVal) && jsbVal.isObject()) { jsbVal.toObject()->getProperty("onTextInput", &g_textInputCallback); + // free globle se::Value before ScriptEngine clean up + se::ScriptEngine::getInstance()->addBeforeCleanupHook([](){ + g_textInputCallback.setUndefined(); + }); } } diff --git a/native/cocos/ui/edit-box/EditBox-win32.cpp b/native/cocos/ui/edit-box/EditBox-win32.cpp index 87dd1ce1f2..a768d311cc 100644 --- a/native/cocos/ui/edit-box/EditBox-win32.cpp +++ b/native/cocos/ui/edit-box/EditBox-win32.cpp @@ -67,6 +67,10 @@ namespace if (global->getProperty("jsb", &jsbVal) && jsbVal.isObject()) { jsbVal.toObject()->getProperty("onTextInput", &g_textInputCallback); + // free globle se::Value before ScriptEngine clean up + se::ScriptEngine::getInstance()->addBeforeCleanupHook([](){ + g_textInputCallback.setUndefined(); + }); } }