Skip to content

Commit

Permalink
Sync issue fixes from creator (cocos2d#17041)
Browse files Browse the repository at this point in the history
* Add EventDispatcher#hasEventListener (sync from creator)

* Fix function wrapper using js object during its gc

* Support more system languages

* Direct log/error for better understanding problems & add sys.now

* Synchronize Editbox APIs

* Synchronize Scheduler.PRIORITY_NON_SYSTEM const

* Upgrade web engine

* Upgrade test cases

* Manually bind EventDispatcher::addCustomEventListener to avoid memory issue

* Manual bind EventListeners’ create to avoid memory issue

* Fix compilation issue when COCOS_DEBUG = 2

* Unify function name of Texture2D::releaseTexture

* Fix compilation issues and update web & bindings-generator

* Fix lua compilation issue

* Use %ld instead of %zd

* Separate FinalizeHook for ref objects and non ref objects

* Fix spine TrackEntry recursive conversion issue by using getter

* Fix crash during Wrappers deallocation (possible to have leak)

* Increase default JS heap to 32 mb

* Update engine version

* Add change log of web engine

* Improve cc.formatStr

* Fix chipmunk crash issues when using setDefaultCollisionHandler

* Add change log for JSB and update web engine ref
  • Loading branch information
pandamicro authored and minggo committed Dec 21, 2016
1 parent bd0789e commit a715e31
Show file tree
Hide file tree
Showing 18 changed files with 377 additions and 190 deletions.
31 changes: 29 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ coocs2d-x-3.14 Dec 19 2016
[NEW] Action: new actions: ResizeBy and ResizeTo
[NEW] Button: can set title label
[NEW] Can disable multi touch on Android
[NEW] EventDispatcher: Add hasEventListener to check listener existance
[NEW] EditBox: add horizontal text alignment
[NEW] Sprite: support scale9 feature
[NEW] Slider: add methods to get _slidBallNormalRenderer
[NEW] Desktop: add a method to toggle between fullscreen and windowed
[NEW] Desktop: add events for window resize, focus and unfocus
[NEW] Mac: supports game controller
[NEW] JSB: add perfromance.now()
[NEW] JSB: add cc.sys.now() and perfromance.now(), the last one is more accurate
[NEW] Lua: add cc.vec3 functions: add, sub and dot
[NEW] Lua: use luajit 2.1.0-beta2

Expand All @@ -25,6 +26,18 @@ coocs2d-x-3.14 Dec 19 2016
[REFINE] Mac: system font enhancement
[REFINE] Linux: build shared lib with -fPIC
[REFINE] Android: use SharedPreferences.apply() to store data
[REFINE] JSB: Increase default JS heap to 32 mb
[REFINE] JSB: Support more system languages
[REFINE] JSB: Direct log/error for better understantding problems
[REFINE] JSB: Separate FinalizeHook for ref objects and non ref objects
[REFINE] Web: Improve overall node construction performance
[REFINE] Web: Improve overall loading process performance
[REFINE] Web: Reduce overall memory usage
[REFINE] Web: Made cc.LabelBMFont and cc.LabelAtlas support texture packing and auto batching
[REFINE] Web: Reimplement a much faster ccui.Scale9Sprite
[REFINE] Web: Reimplement a much faster cc.DrawNode WebGL renderer
[REFINE] Web: Use stack to avoid recursive call in transform, onEnter, onExit etc, reduce call stack depth


[FIX] AsstsManagerEx: project.manifest may be downloaded twice
[FIX] AudioEngine: can not play large ogg file
Expand Down Expand Up @@ -74,11 +87,25 @@ coocs2d-x-3.14 Dec 19 2016
[FIX] Linux: Application::openURL can not work
[FIX] Desktop: crash upon exit when NotificationNode exists
[FIX] Spine: color bug
[FIX] Console: doesn't support `--ap` parameter
[FIX] Lua: result of radian2angle is wrong
[FIX] Lua: iskindof_ doesn't work correctly
[FIX] Lua: new lua project crashes compiling with VS2015 release mode
[FIX] JSB: `jsb.addRoot is not a function` error caused by cc.GLProgramState.setUniformCallback
[FIX] Console: doesn't support `--ap` parameter
[FIX] JSB: Fix spine TrackEntry conversion crash issue
[FIX] JSB: Fix CallbackWrapper and FunctionWrapper crash during deallocation in new memory model
[FIX] JSB: Fix event object memory issue by manually bind EventDispatcher::addCustomEventListener
[FIX] JSB: Fix chipmunk crash issues when using setDefaultCollisionHandler
[FIX] JSB: Fix compilation issues when COCOS_DEBUG = 2
[FIX] JSB: Unify function name of Texture2D::releaseTexture
[FIX] Web: Fix spine blend function inconsistency between web and jsb
[FIX] Web: Fix particle system load from plist generated by x-studio365
[FIX] Web: Fix doEnumerateRecursive(node, name, callback) always return undefined issue
[FIX] Web: Change bright style on 'setEnabled' call of ccui.Widget
[FIX] Web: Fix Editbox can't input in full screen mode
[FIX] Web: Fix texture issue on some Android devices by always set vertexAttribPointer
[FIX] Web: Made xhr ontimeout callback work on all browsers
[FIX] Web: Fix clear color not normalized issue

cocos2d-x-3.13.1 Sep 13 2016

Expand Down
4 changes: 2 additions & 2 deletions cocos/platform/CCGLView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void GLView::handleTouchesMove(int num, intptr_t ids[], float xs[], float ys[],
continue;
}

CCLOGINFO("Moving touches with id: %d, x=%f, y=%f, force=%f, maxFource=%f", id, x, y, force, maxForce);
CCLOGINFO("Moving touches with id: %d, x=%f, y=%f, force=%f, maxFource=%f", (int)id, x, y, force, maxForce);
Touch* touch = g_touches[iter->second];
if (touch)
{
Expand Down Expand Up @@ -417,7 +417,7 @@ void GLView::handleTouchesOfEndOrCancel(EventTouch::EventCode eventCode, int num
Touch* touch = g_touches[iter->second];
if (touch)
{
CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y);
CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", (int)id, x, y);
touch->setTouchInfo(iter->second, (x - _viewPortRect.origin.x) / _scaleX,
(y - _viewPortRect.origin.y) / _scaleY);

Expand Down
39 changes: 22 additions & 17 deletions cocos/scripting/js-bindings/manual/ScriptingCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,14 @@ void ScriptingCore::createGlobalContext() {

// Removed from Spidermonkey 19.
//JS_SetCStringsAreUTF8();
_rt = JS_NewRuntime(8L * 1024L * 1024L);
_rt = JS_NewRuntime(32L * 1024L * 1024L);
JS_SetGCParameter(_rt, JSGC_MAX_BYTES, 0xffffffff);

JS_SetTrustedPrincipals(_rt, &shellTrustedPrincipals);
JS_SetSecurityCallbacks(_rt, &securityCallbacks);
JS_SetNativeStackQuota(_rt, JSB_MAX_STACK_QUOTA);

_cx = JS_NewContext(_rt, 8192);
_cx = JS_NewContext(_rt, 32 * 1024);

// Removed in Firefox v27
// JS_SetOptions(this->_cx, JSOPTION_TYPE_INFERENCE);
Expand Down Expand Up @@ -1438,7 +1438,7 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve

for (const auto& touch : touches)
{
JS::RootedValue jsret(_cx, OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, touch, typeClassTouch, "cocos2d::Touch")));
JS::RootedValue jsret(_cx, OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, touch, typeClassTouch)));
if (!JS_SetElement(_cx, jsretArr, count, jsret))
{
break;
Expand All @@ -1451,15 +1451,14 @@ bool ScriptingCore::handleTouchesEvent(void* nativeObj, cocos2d::EventTouch::Eve
{
jsval dataVal[2];
dataVal[0] = OBJECT_TO_JSVAL(jsretArr);
dataVal[1] = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, event, typeClassEvent, "cocos2d::EventTouch"));
dataVal[1] = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, event, typeClassEvent));
ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet);
}

for (auto& touch : touches)
{
removeJSObject(_cx, touch);
}

removeJSObject(_cx, event);

return ret;
Expand All @@ -1485,8 +1484,8 @@ bool ScriptingCore::handleTouchEvent(void* nativeObj, cocos2d::EventTouch::Event
js_type_class_t *typeClassEvent = js_get_type_from_native<cocos2d::EventTouch>((cocos2d::EventTouch*)event);

jsval dataVal[2];
dataVal[0] = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, touch, typeClassTouch, "cocos2d::Touch"));
dataVal[1] = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, event, typeClassEvent, "cocos2d::EventTouch"));
dataVal[0] = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, touch, typeClassTouch));
dataVal[1] = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, event, typeClassEvent));

ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 2, dataVal, jsvalRet);
}
Expand Down Expand Up @@ -1514,7 +1513,7 @@ bool ScriptingCore::handleMouseEvent(void* nativeObj, cocos2d::EventMouse::Mouse
if (p)
{
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::EventMouse>((cocos2d::EventMouse*)event);
jsval dataVal = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, event, typeClass, "cocos2d::EventMouse"));
jsval dataVal = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, event, typeClass));
ret = executeFunctionWithOwner(OBJECT_TO_JSVAL(p->obj), funcName.c_str(), 1, &dataVal, jsvalRet);

removeJSObject(_cx, event);
Expand Down Expand Up @@ -1611,7 +1610,7 @@ bool ScriptingCore::handleKeyboardEvent(void* nativeObj, cocos2d::EventKeyboard:
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::EventKeyboard>((cocos2d::EventKeyboard*)event);
jsval args[2] = {
int32_to_jsval(_cx, (int32_t)keyCode),
OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, event, typeClass, "cocos2d::EventKeyboard"))
OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(_cx, event, typeClass))
};

if (isPressed)
Expand Down Expand Up @@ -1662,7 +1661,7 @@ int ScriptingCore::executeCustomTouchesEvent(EventTouch::EventCode eventType,
{
js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Touch>(touch);

jsval jsret = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(this->_cx, touch, typeClass, "cocos2d::Touch"));
jsval jsret = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(this->_cx, touch, typeClass));
JS::RootedValue jsval(_cx, jsret);
if (!JS_SetElement(this->_cx, jsretArr, count, jsval)) {
break;
Expand Down Expand Up @@ -1690,7 +1689,7 @@ int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType, Touc
std::string funcName = getTouchFuncName(eventType);

js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Touch>(touch);
jsval jsTouch = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(this->_cx, touch, typeClass, "cocos2d::Touch"));
jsval jsTouch = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(this->_cx, touch, typeClass));

executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsTouch, &retval);

Expand All @@ -1709,7 +1708,7 @@ int ScriptingCore::executeCustomTouchEvent(EventTouch::EventCode eventType,
std::string funcName = getTouchFuncName(eventType);

js_type_class_t *typeClass = js_get_type_from_native<cocos2d::Touch>(touch);
jsval jsTouch = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(this->_cx, touch, typeClass, "cocos2d::Touch"));
jsval jsTouch = OBJECT_TO_JSVAL(jsb_get_or_create_weak_jsobject(this->_cx, touch, typeClass));

executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), funcName.c_str(), 1, &jsTouch, retval);

Expand Down Expand Up @@ -2308,12 +2307,16 @@ JSObject* jsb_create_weak_jsobject(JSContext *cx, void *native, js_type_class_t
JS::RootedObject parent(cx, typeClass->parentProto.ref());
JS::RootedObject jsObj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent));
auto proxy = jsb_new_proxy(native, jsObj);
js_add_FinalizeHook(cx, jsObj, false);

#if ! CC_ENABLE_GC_FOR_NATIVE_OBJECTS
JS::AddNamedObjectRoot(cx, &proxy->obj, debug);
#else
#if COCOS2D_DEBUG > 1
CCLOG("++++++WEAK_REF++++++ Cpp(%s): %p - JS: %p", debug, native, jsObj.get());
if (debug != nullptr)
{
CCLOG("++++++WEAK_REF++++++ Cpp(%s): %p - JS: %p", debug, native, jsObj.get());
}
#endif // COCOS2D_DEBUG
#endif // CC_ENABLE_GC_FOR_NATIVE_OBJECTS
return jsObj;
Expand All @@ -2336,7 +2339,7 @@ JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_ty
js_proxy_t* newproxy = jsb_new_proxy(ref, jsObj);
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
ref->retain();
js_add_FinalizeHook(cx, jsObj);
js_add_FinalizeHook(cx, jsObj, true);
#if COCOS2D_DEBUG > 1
CCLOG("++++++RETAINED++++++ Cpp(%s): %p - JS: %p", debug, ref, jsObj.get());
#endif // COCOS2D_DEBUG
Expand Down Expand Up @@ -2398,7 +2401,7 @@ void jsb_ref_init(JSContext* cx, JS::Heap<JSObject*> *obj, Ref* ref, const char*
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
(void)ref;
JS::RootedObject jsObj(cx, *obj);
js_add_FinalizeHook(cx, jsObj);
js_add_FinalizeHook(cx, jsObj, true);
// don't retain it, already retained
#if COCOS2D_DEBUG > 1
CCLOG("++++++RETAINED++++++ Cpp(%s): %p - JS: %p", debug, ref, jsObj.get());
Expand All @@ -2418,7 +2421,7 @@ void jsb_ref_autoreleased_init(JSContext* cx, JS::Heap<JSObject*> *obj, Ref* ref
(void)obj;
ref->retain();
JS::RootedObject jsObj(cx, *obj);
js_add_FinalizeHook(cx, jsObj);
js_add_FinalizeHook(cx, jsObj, true);
#else
// don't autorelease it, since it is already autoreleased
JS::AddNamedObjectRoot(cx, obj, debug);
Expand All @@ -2440,7 +2443,9 @@ void jsb_ref_rebind(JSContext* cx, JS::HandleObject jsobj, js_proxy_t *proxy, co
// Rebind js obj with new action
js_proxy_t* newProxy = jsb_new_proxy(newRef, jsobj);

#if !CC_ENABLE_GC_FOR_NATIVE_OBJECTS
#if CC_ENABLE_GC_FOR_NATIVE_OBJECTS
CC_UNUSED_PARAM(newProxy);
#else
JS::AddNamedObjectRoot(cx, &newProxy->obj, debug);
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions cocos/scripting/js-bindings/manual/ScriptingCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <memory>
#include <chrono>

#define ENGINE_VERSION "Cocos2d-JS v3.13"
#define ENGINE_VERSION "Cocos2d-JS v3.14"

void js_log(const char *format, ...);

Expand Down Expand Up @@ -665,15 +665,15 @@ JSObject* jsb_ref_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_ty
* If it can't find it, it will create a new one associating it to Ref
* Call this function for objects that might return an already existing copy when you create them. For example, `Animation3D::create()`;
*/
JSObject* jsb_ref_autoreleased_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug);
JSObject* jsb_ref_autoreleased_get_or_create_jsobject(JSContext *cx, cocos2d::Ref *ref, js_type_class_t *typeClass, const char* debug=nullptr);

/**
* It will try to get the associated JSObjct for the native object.
* If it can't find it, it will create a new one associating it to the native object.
* The reference created from JSObject to native object is weak because it won't retain it.
* The behavior is exactly the same with 'jsb_ref_get_or_create_jsobject' when CC_ENABLE_GC_FOR_NATIVE_OBJECTS deactivated.
*/
CC_JS_DLL JSObject* jsb_get_or_create_weak_jsobject(JSContext *cx, void *native, js_type_class_t *typeClass, const char* debug);
CC_JS_DLL JSObject* jsb_get_or_create_weak_jsobject(JSContext *cx, void *native, js_type_class_t *typeClass, const char* debug=nullptr);

/**
* Register finalize hook and its owner as an entry in _js_hook_owner_map,
Expand Down
Loading

0 comments on commit a715e31

Please sign in to comment.