Projects > cpp > Issues > Bug #1617

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Some improvements for JS Bindings

Bug #1617 [Closed]
dumganhar 2012-12-18 03:53 . Updated almost 4 years ago

1) Changed <code>cc.REPEAT_FOREVER = - 1</code> to <code>cc.REPEAT_FOREVER = 0xffffffff</code>

****: If cc.REPEAT_FOREVER = –1, it will be a very big double value after converting it to double by <code>JS_ValueToNumber</code> on android.
Then cast it to unsigned int, the value will be 0. The schedule will not be able to work.
I don’t know why this occurs only on android.
****: Instead of passing –1 to it, I assign it with max value of unsigned int in c++.
h3. 2) Added two helper function, cc.ArrayGetIndexOfObject and cc.ArrayContainsObject.
h3. 3) Added JSScheduleWrapper::removeTargetForNativeNode to avoid memory leaks.
h3. 4) Improvments for JSTouchDelegate. Added four functions as follows:
<pre>
// Set the touch delegate to map by using the key .
static void setDelegateForJSObject;
// Get the touch delegate by the key .
static JSTouchDelegate** getDelegateForJSObject;
// Remove the delegate by the key .
static void removeDelegateForJSObject;
void unregisterTouchDelegate;
</pre>
And exported <code>cc.unregisterTouchDelegate;</code> to js.
Fix a memory leak for JSTouchDelegate by making it as an autorelease object.
h3. 5) Don’t add js callback function to the reserved slot of object.
[Reason]: The target object may execute more than one schedule.
Therefore, previous js callback function will be replaced
by the current one. For example:
<pre>
this.scheduleOnce { temporary function 1 }, 0.5);
this.scheduleOnce { temporary function 2 }, 0.5);
</pre>
In this case, the temporary function 1 will be removed from reserved slot 0.
And temporary function 2 will be set to reserved slot 0 of this object.
If gc is triggered before the <code>JSScheduleWrapper::scheduleFunc</code> is invoked,
crash will happen. You could simply reproduce it by adding **jsc*.garbageCollect;* after scheduleOnce.
**[Solution]* Because one schedule corresponds to one <code>JSScheduleWrapper</code>, we root
the js callback function in <code>JSScheduleWrapper::setJSCallbackFunc</code> and unroot it
at the destructor of JSScheduleWrapper.

dumganhar 2012-12-20 06:25
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset commit:c037d156529a1c32845d9649729c6dc8181b3be1.

Atom PDF

Status:Closed
Start date:2012-12-18
Priority:Normal
Due date:
Assignee:-
% Done:

100%

Category:-
Target version:-

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.