diff --git a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.cpp b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.cpp index c3138222fd..0912dfb327 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/chakracore/Utils.cpp @@ -125,8 +125,8 @@ namespace se { if (obj == nullptr) { obj = Object::_createJSObject(nullptr, jsValue); - obj->root(); } + obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC data->setObject(obj); obj->release(); } diff --git a/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp b/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp index 96fe687b6d..6b5e854163 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/jsc/Utils.cpp @@ -158,8 +158,8 @@ namespace se { if (obj == nullptr) { obj = Object::_createJSObject(nullptr, jsobj); - obj->root(); } + obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC data->setObject(obj); obj->release(); } diff --git a/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.cpp b/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.cpp index 52dbde5f95..9191431dcc 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/sm/Utils.cpp @@ -135,8 +135,8 @@ namespace se { if (object == nullptr) { object = Object::_createJSObject(nullptr, jsval.toObjectOrNull()); - object->root(); } + object->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC v->setObject(object); object->release(); } @@ -154,8 +154,6 @@ namespace se { } } - // --- Sets the return value for a function - void setReturnValue(JSContext* cx, const Value& data, const JS::CallArgs& argv) { JS::RootedValue rval(cx); diff --git a/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp b/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp index 10140df29f..5ba2fef38d 100644 --- a/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp +++ b/native/cocos/scripting/js-bindings/jswrapper/v8/Utils.cpp @@ -107,8 +107,8 @@ namespace se { if (obj == nullptr) { obj = Object::_createJSObject(nullptr, jsObj.ToLocalChecked()); - obj->root(); } + obj->root(); // Root it here since it will be unrooted in at the end of SE_BIND_FUNC v->setObject(obj); obj->release(); } diff --git a/native/cocos/scripting/js-bindings/manual/jsb_conversions.hpp b/native/cocos/scripting/js-bindings/manual/jsb_conversions.hpp index 9271efa21e..c42da9b2da 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_conversions.hpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_conversions.hpp @@ -276,7 +276,6 @@ bool native_ptr_to_rooted_seval(typename std::enable_if(v); assert(cls != nullptr); obj = se::Object::createObjectWithClass(cls); @@ -287,14 +286,17 @@ bool native_ptr_to_rooted_seval(typename std::enable_ifsecond; + assert(obj->isRooted()); if (isReturnCachedValue != nullptr) { *isReturnCachedValue = true; } + // CCLOG("return cached object: %s, se::Object:%p, native: %p", typeid(*v).name(), obj, v); } ret->setObject(obj); @@ -353,7 +355,6 @@ bool native_ptr_to_rooted_seval(typename std::enable_ifroot(); @@ -363,14 +364,17 @@ bool native_ptr_to_rooted_seval(typename std::enable_ifsecond; + assert(obj->isRooted()); if (isReturnCachedValue != nullptr) { *isReturnCachedValue = true; } + // CCLOG("return cached object: %s, se::Object:%p, native: %p", typeid(*v).name(), obj, v); } ret->setObject(obj); diff --git a/native/cocos/scripting/js-bindings/manual/jsb_creator_manual.cpp b/native/cocos/scripting/js-bindings/manual/jsb_creator_manual.cpp index 3e63921cc2..eca3767859 100644 --- a/native/cocos/scripting/js-bindings/manual/jsb_creator_manual.cpp +++ b/native/cocos/scripting/js-bindings/manual/jsb_creator_manual.cpp @@ -34,7 +34,9 @@ static bool js_creator_PhysicsContactListener_setPreSolve(se::State& s) CC_UNUSED bool ok = true; se::ValueArray args; args.resize(1); - ok &= native_ptr_to_rooted_seval(larg0, __jsb_b2Contact_class, &args[0]); + bool fromCache = false; + ok &= native_ptr_to_rooted_seval(larg0, __jsb_b2Contact_class, &args[0], &fromCache); + se::Value rval; se::Object* thisObj = jsThis.isObject() ? jsThis.toObject() : nullptr; se::Object* funcObj = jsFunc.toObject(); diff --git a/native/tools/tojs/creator.ini b/native/tools/tojs/creator.ini index f4cf924aac..37700cacf0 100755 --- a/native/tools/tojs/creator.ini +++ b/native/tools/tojs/creator.ini @@ -34,7 +34,7 @@ replace_headers = CCScale9Sprite.h::creator/CCScale9Sprite.h,CCGraphicsNode.h::c # what classes to produce code for. You can use regular expressions here. When testing the regular # expression, it will be enclosed in "^$", like this: "^Menu*$". -classes = Scale9SpriteV2 GraphicsNode PhysicsDebugDraw PhysicsUtils PhysicsContactListener PhysicsAABBQueryCallback PhysicsRayCastCallback PhysicsWorldManifoldWrapper PhysicsContactImpulse CameraNode +classes = Scale9SpriteV2 GraphicsNode PhysicsDebugDraw PhysicsUtils PhysicsContactListener PhysicsAABBQueryCallback PhysicsRayCastCallback PhysicsWorldManifoldWrapper PhysicsManifoldWrapper PhysicsContactImpulse CameraNode classes_need_extend = Scale9SpriteV2 GraphicsNode @@ -50,6 +50,7 @@ skip = PhysicsDebugDraw::[DrawPolygon DrawSolidPolygon DrawCircle DrawSolidCircl PhysicsAABBQueryCallback::[ReportFixture getFixtures], PhysicsRayCastCallback::[ReportFixture getFixtures getNormals getPoints], PhysicsWorldManifoldWrapper::[init getb2WorldManifold], + PhysicsManifoldWrapper::[init], PhysicsContactImpulse::[init], CameraNode::[(.*)Visit] @@ -71,4 +72,4 @@ base_classes_to_skip = Ref abstract_classes = Helper LayoutManager AbstractCheckButton -classes_owned_by_cpp = PhysicsContactImpulse +classes_owned_by_cpp = PhysicsContactImpulse PhysicsWorldManifoldWrapper PhysicsManifoldWrapper