mirror of https://github.com/axmolengine/axmol.git
Merge pull request #14805 from pandamicro/v3.10
Fix JSB issues on win32
This commit is contained in:
commit
69a6406661
|
@ -925,10 +925,8 @@ bool ScriptingCore::executeScript(JSContext *cx, uint32_t argc, jsval *vp)
|
|||
|
||||
bool ScriptingCore::forceGC(JSContext *cx, uint32_t argc, jsval *vp)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM != CC_PLATFORM_WIN32
|
||||
JSRuntime *rt = JS_GetRuntime(cx);
|
||||
JS_GC(rt);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -970,6 +970,9 @@ bool JSB_cpSpaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp)
|
|||
JSB_PRECONDITION2(argc==7, cx, false, "Invalid number of arguments");
|
||||
|
||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||
JS::RootedValue spaceVal(cx, args.get(0));
|
||||
JS::RootedObject jsspace(cx);
|
||||
JS_ValueToObject(cx, spaceVal, &jsspace);
|
||||
|
||||
// args
|
||||
cpSpace *space = nullptr;
|
||||
|
@ -978,7 +981,6 @@ bool JSB_cpSpaceAddCollisionHandler(JSContext *cx, uint32_t argc, jsval *vp)
|
|||
bool ok = jsval_to_opaque(cx, jsarg, (void**)&space);
|
||||
JSB_PRECONDITION(ok, "Error parsing arguments");
|
||||
|
||||
JS::RootedObject jsspace(cx, jsarg.toObjectOrNull());
|
||||
return __jsb_cpSpace_addCollisionHandler(cx, vp, argvp, jsspace, space, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -2449,7 +2449,19 @@ bool js_cocos2dx_ActionInterval_repeat(JSContext *cx, uint32_t argc, jsval *vp)
|
|||
|
||||
cocos2d::Repeat* action = new (std::nothrow) cocos2d::Repeat;
|
||||
action->initWithAction(cobj, timesInt);
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
// Using jsb_ref_rebind will cause GC crash on win32
|
||||
action->autorelease();
|
||||
// Unlink old native object
|
||||
JS::RemoveObjectRoot(cx, &proxy->obj);
|
||||
jsb_remove_proxy(proxy);
|
||||
// Relink with new object
|
||||
js_proxy_t* newProxy = jsb_new_proxy(action, obj);
|
||||
JS::AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::Repeat");
|
||||
#else // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
jsb_ref_rebind(cx, obj, proxy, cobj, action, "cocos2d::Repeat");
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
|
||||
args.rval().set(OBJECT_TO_JSVAL(obj));
|
||||
return true;
|
||||
|
@ -2471,7 +2483,19 @@ bool js_cocos2dx_ActionInterval_repeatForever(JSContext *cx, uint32_t argc, jsva
|
|||
cocos2d::RepeatForever* action = new (std::nothrow) cocos2d::RepeatForever;
|
||||
action->initWithAction(cobj);
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
// Using jsb_ref_rebind will cause GC crash on win32
|
||||
action->autorelease();
|
||||
// Unlink old native object
|
||||
JS::RemoveObjectRoot(cx, &proxy->obj);
|
||||
jsb_remove_proxy(proxy);
|
||||
// Relink with new object
|
||||
js_proxy_t* newProxy = jsb_new_proxy(action, jsobj);
|
||||
JS::AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::RepeatForever");
|
||||
#else // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
jsb_ref_rebind(cx, jsobj, proxy, cobj, action, "cocos2d::RepeatForever");
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
|
||||
args.rval().set(OBJECT_TO_JSVAL(jsobj));
|
||||
return true;
|
||||
}
|
||||
|
@ -2501,7 +2525,18 @@ bool js_cocos2dx_ActionInterval_speed(JSContext *cx, uint32_t argc, jsval *vp)
|
|||
|
||||
cocos2d::Speed* action = new (std::nothrow) cocos2d::Speed;
|
||||
action->initWithAction(cobj, speed);
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
// Using jsb_ref_rebind will cause GC crash on win32
|
||||
action->autorelease();
|
||||
// Unlink old native object
|
||||
JS::RemoveObjectRoot(cx, &proxy->obj);
|
||||
jsb_remove_proxy(proxy);
|
||||
// Relink with new object
|
||||
js_proxy_t* newProxy = jsb_new_proxy(action, obj);
|
||||
JS::AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::Speed");
|
||||
#else // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
jsb_ref_rebind(cx, obj, proxy, cobj, action, "cocos2d::Speed");
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
|
||||
args.rval().set(OBJECT_TO_JSVAL(obj));
|
||||
return true;
|
||||
|
@ -2809,8 +2844,19 @@ bool js_cocos2dx_ActionInterval_easing(JSContext *cx, uint32_t argc, jsval *vp)
|
|||
}
|
||||
}
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
// Using jsb_ref_rebind will cause GC crash on win32
|
||||
newAction->autorelease();
|
||||
// Unlink old native object
|
||||
JS::RemoveObjectRoot(cx, &proxy->obj);
|
||||
jsb_remove_proxy(proxy);
|
||||
// Relink with new object
|
||||
js_proxy_t* newProxy = jsb_new_proxy(newAction, jsobj);
|
||||
JS::AddNamedObjectRoot(cx, &newProxy->obj, "cocos2d::EaseAction");
|
||||
#else // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
// Unbind existing proxy binding with cobj, and rebind with the new action
|
||||
jsb_ref_rebind(cx, jsobj, proxy, oldAction, newAction, "cocos2d::EaseAction");
|
||||
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
|
||||
args.rval().set(OBJECT_TO_JSVAL(jsobj));
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue