mirror of https://github.com/axmolengine/axmol.git
Fix scheduler callback target lost issue
This commit is contained in:
parent
84d4b185f8
commit
d1e9a149c4
|
@ -734,26 +734,7 @@ JSCallbackWrapper::JSCallbackWrapper(JS::HandleValue owner)
|
||||||
|
|
||||||
JSCallbackWrapper::~JSCallbackWrapper()
|
JSCallbackWrapper::~JSCallbackWrapper()
|
||||||
{
|
{
|
||||||
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
reset();
|
||||||
JS::RootedValue ownerVal(cx, _owner);
|
|
||||||
if (!ownerVal.isNullOrUndefined())
|
|
||||||
{
|
|
||||||
JS::RootedValue target(cx, _jsCallback);
|
|
||||||
if (!target.isNullOrUndefined())
|
|
||||||
{
|
|
||||||
js_remove_object_reference(ownerVal, target);
|
|
||||||
}
|
|
||||||
target.set(_jsThisObj);
|
|
||||||
if (!target.isNullOrUndefined())
|
|
||||||
{
|
|
||||||
js_remove_object_reference(ownerVal, target);
|
|
||||||
}
|
|
||||||
target.set(_extraData);
|
|
||||||
if (!target.isNullOrUndefined())
|
|
||||||
{
|
|
||||||
js_remove_object_reference(ownerVal, target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSCallbackWrapper::setJSCallbackFunc(JS::HandleValue func) {
|
void JSCallbackWrapper::setJSCallbackFunc(JS::HandleValue func) {
|
||||||
|
@ -825,6 +806,33 @@ const jsval JSCallbackWrapper::getJSExtraData() const
|
||||||
return _extraData;
|
return _extraData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JSCallbackWrapper::reset()
|
||||||
|
{
|
||||||
|
JSContext* cx = ScriptingCore::getInstance()->getGlobalContext();
|
||||||
|
JS::RootedValue ownerVal(cx, _owner);
|
||||||
|
if (!ownerVal.isNullOrUndefined())
|
||||||
|
{
|
||||||
|
JS::RootedValue target(cx, _jsCallback);
|
||||||
|
if (!target.isNullOrUndefined())
|
||||||
|
{
|
||||||
|
js_remove_object_reference(ownerVal, target);
|
||||||
|
}
|
||||||
|
target.set(_jsThisObj);
|
||||||
|
if (!target.isNullOrUndefined())
|
||||||
|
{
|
||||||
|
js_remove_object_reference(ownerVal, target);
|
||||||
|
}
|
||||||
|
target.set(_extraData);
|
||||||
|
if (!target.isNullOrUndefined())
|
||||||
|
{
|
||||||
|
js_remove_object_reference(ownerVal, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_jsCallback = JS::NullValue();
|
||||||
|
_jsThisObj = JS::NullValue();
|
||||||
|
_extraData = JS::NullValue();
|
||||||
|
}
|
||||||
|
|
||||||
// cc.CallFunc.create( func, this, [data])
|
// cc.CallFunc.create( func, this, [data])
|
||||||
// cc.CallFunc.create( func )
|
// cc.CallFunc.create( func )
|
||||||
static bool js_callFunc(JSContext *cx, uint32_t argc, jsval *vp)
|
static bool js_callFunc(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
@ -1217,6 +1225,7 @@ void JSScheduleWrapper::removeTargetForJSObject(JS::HandleObject jsTargetObj, JS
|
||||||
free(removed);
|
free(removed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
target->reset();
|
||||||
dump();
|
dump();
|
||||||
CCLOGINFO("removeTargetForJSObject end");
|
CCLOGINFO("removeTargetForJSObject end");
|
||||||
}
|
}
|
||||||
|
@ -1266,8 +1275,11 @@ void JSScheduleWrapper::scheduleFunc(float dt)
|
||||||
if(!callback.isNullOrUndefined()) {
|
if(!callback.isNullOrUndefined()) {
|
||||||
JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(1, &data);
|
JS::HandleValueArray args = JS::HandleValueArray::fromMarkedLocation(1, &data);
|
||||||
JS::RootedValue retval(cx);
|
JS::RootedValue retval(cx);
|
||||||
JS::RootedObject callbackTarget(cx, getJSCallbackThis().toObjectOrNull());
|
JS::RootedValue targetVal(cx, getJSCallbackThis());
|
||||||
JS_CallFunctionValue(cx, callbackTarget, callback, args, &retval);
|
if (!targetVal.isNullOrUndefined()) {
|
||||||
|
JS::RootedObject target(cx, targetVal.toObjectOrNull());
|
||||||
|
JS_CallFunctionValue(cx, target, callback, args, &retval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,8 @@ public:
|
||||||
const jsval getJSCallbackFunc() const;
|
const jsval getJSCallbackFunc() const;
|
||||||
const jsval getJSCallbackThis() const;
|
const jsval getJSCallbackThis() const;
|
||||||
const jsval getJSExtraData() const;
|
const jsval getJSExtraData() const;
|
||||||
|
|
||||||
|
void reset();
|
||||||
protected:
|
protected:
|
||||||
JS::Heap<JS::Value> _owner;
|
JS::Heap<JS::Value> _owner;
|
||||||
JS::Heap<JS::Value> _jsCallback;
|
JS::Heap<JS::Value> _jsCallback;
|
||||||
|
|
Loading…
Reference in New Issue