Narendrabrsoft / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

CCSchduler unscheduleUpdate doesn't work when inside tick #36

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Calling unscheduleUpdate while inside a tick results in an index out of bounds 
exception. For the regular unschedule method there is additional logic, but not 
for scheduleUpdate. Stack trace here:

12-21 23:47:57.308: ERROR/AndroidRuntime(27307):     at 
java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
12-21 23:47:57.308: ERROR/AndroidRuntime(27307):     at 
java.util.ArrayList.get(ArrayList.java:311)
12-21 23:47:57.308: ERROR/AndroidRuntime(27307):     at 
org.cocos2d.actions.CCScheduler.tick(CCScheduler.java:172)
12-21 23:47:57.308: ERROR/AndroidRuntime(27307):     at 
org.cocos2d.nodes.CCDirector.drawCCScene(CCDirector.java:673)
12-21 23:47:57.308: ERROR/AndroidRuntime(27307):     at 
org.cocos2d.nodes.CCDirector.onDrawFrame(CCDirector.java:659)
12-21 23:47:57.308: ERROR/AndroidRuntime(27307):     at 
android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1332)
12-21 23:47:57.308: ERROR/AndroidRuntime(27307):     at 
android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)

Original issue reported on code.google.com by ghemp...@gmail.com on 22 Dec 2010 at 8:00

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
The problem is in one thread.

In tick we have:
            int len2 = updates0.size();
            for(int i=0; i < len2; ++i) {
                tListEntry e = updates0.get(i);
And in callback we call unsheduleUpdate:
        entry.list.remove(entry.entry);
len2 should be decreased, i should be decreased.

We can mark for example entry in execution as beeing removed. Theck this after 
update and remove if this is needed. Have to be looked more carefully.

Original comment by opengen...@gmail.com on 22 Dec 2010 at 9:47

GoogleCodeExporter commented 8 years ago
Try it now.

Original comment by opengen...@gmail.com on 26 Dec 2010 at 11:10

GoogleCodeExporter commented 8 years ago
Still seem to get the index out of bounds exception.

Original comment by ghemp...@gmail.com on 28 Dec 2010 at 7:26

GoogleCodeExporter commented 8 years ago
    public void update(float d) {
        Log.v("DEBUG", "in update");
        CCScheduler.sharedScheduler().unscheduleUpdate(this);
        Log.v("DEBUG", "unscheduled Update");
    }

This works for me without exceptions. May be some differences in my current 
branch. Please check gc-optimization. It should be stable (it is stable for 
me). I'm doing some work on optimization there.

Original comment by opengen...@gmail.com on 29 Dec 2010 at 12:26