ZhouWeikuan / cocos2d

cocos2d for android, based on cocos2d-android-0.82, and now ported from cocos2d-iphone 0.99.4. The googlecode address is here: http://code.google.com/p/cocos2d-android-1/ . There are several demos to watch.
610 stars 291 forks source link

changing scene caused white textures #20

Open zmeda opened 13 years ago

zmeda commented 13 years ago

Sometimes CCDirector.sharedDirector().replaceScene causes white textures on showed scene.

dustinanon commented 13 years ago

I also have this issue from time to time, but I haven't tried to debug it yet... might be a hard one to catch.

dustinanon commented 13 years ago

After the latest patch, this bug is happening much more frequently, I would say it's almost 50/50 that a texture displays as a white box now.

dustinanon commented 13 years ago

Oh, also this happens when calling runWithScene() too

dustinanon commented 13 years ago

Any news on this? Or reason why it's happening? This is pretty frustrating, and a possible deal-breaker...

dustinanon commented 13 years ago

bump..

irwinb commented 13 years ago

Hello dustinano,

This problems occurs when you try to load a texture while not inside the GL thread. I ran into the same problem but did not spend enough time to look into the source code to find out why it happens only sometimes. It must be a time-related issue.

To make a quick and dirty solution, I used a combination of a lock and the GLSurfaceView queueEvent system. Let me know if you need me to elaborate..

If I'm not doing anything wrong..I hope there is a solution to this within the source because this is something that a user should not have to do.

dustinanon commented 13 years ago

I just got back from a vacation to the states. That makes absolute sense, it seems that there are a few places in the code which had some pitfall race conditions... maybe I'll address those and publish a patch. If I need some more guidance, I'll surely get back to you.

Thanks for the point in the right direction!

dustinanon commented 13 years ago

After stepping through the code, it seems like this should already be taken care of, if you look between CCTexture2D.setLoader(), GLResourceHelper.addLoader(), GLResourceHelper.update(), and CCDirector.drawCCScene(), you would notice that the texture adds a Task to a taskQueue to be performed only during the GLThread's update...

It's strange that calling the loading itself from the GLThread fixes the issue... but it's worth a try anyway!

dustinanon commented 13 years ago

I just committed some code to correct the issue. Like you said, it is quick and dirty, but it gets the job done.

Check https://github.com/dustinanon/cocos2d/commit/8b577bd87d8227abb8a165f46c0f63d2a2d8f069

irwinb commented 13 years ago

Sweet. Thanks for looking into it :)

dustinanon commented 13 years ago

I just had this exception come up. I wonder if it might be a hint towards the cause of the white textures:


E/AndroidRuntime( 6013): FATAL EXCEPTION: GLThread 28
E/AndroidRuntime( 6013): java.util.ConcurrentModificationException
E/AndroidRuntime( 6013):    at java.util.WeakHashMap$HashIterator.next(WeakHashMap.java:165)
E/AndroidRuntime( 6013):    at org.cocos2d.opengl.GLResourceHelper$2.perform(GLResourceHelper.java:88)
E/AndroidRuntime( 6013):    at org.cocos2d.opengl.GLResourceHelper.update(GLResourceHelper.java:123)
E/AndroidRuntime( 6013):    at org.cocos2d.nodes.CCDirector.drawCCScene(CCDirector.java:700)
E/AndroidRuntime( 6013):    at org.cocos2d.nodes.CCDirector.onDrawFrame(CCDirector.java:665)
E/AndroidRuntime( 6013):    at org.cocos2d.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1245)
E/AndroidRuntime( 6013):    at org.cocos2d.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1056)
dustinanon commented 13 years ago

Okay, that might not be the EXACT issue, but concurrency is definitely the problem. I modified CCTexture2D by adding the following calls to the logger in CCTexture2D.loadTexture(GL10 gl):

    public void loadTexture(GL10 gl) {
        if (_name == 0) {
            int[] textures = new int[1];
            gl.glGenTextures(1, textures, 0);

            _name = textures[0];

            Log.w("GL TEXTURE NAME", "GL TEXTURE NAME: " + _name);
            Log.w("Thread Name", "THREAD NAME: " + Thread.currentThread().getName());

            /** wtf is going on with this white texture? */
            Log.w("GL Errors", "GL ERRORS: " + gl.glGetError());

            applyTexParameters(gl);

            /** wtf is going on with this white texture? */
            Log.w("GL Errors", "GL ERRORS: " + gl.glGetError());

            // this shouldn't be so never, but if so, needs to be found where
            // texture reloading is in progress 
            if(mBitmap == null)
                return;

            GLUtils.texImage2D(GL_TEXTURE_2D, 0, mBitmap, 0);
            mBitmap.recycle();
            mBitmap = null;
        }
    }

and when I tried to load 15 textures, I got the following log (cleaned for relevancy):

W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 315638026
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 534244737
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 1505553220
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -1563003837
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -867317458
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -1700480907
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -2028555960
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 1841779351
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -1054071278
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -1422854359
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -1408567796
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 1363318443
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 1671093174
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -553484899
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 0
W/Thread Name(13436): THREAD NAME: Thread-29
W/GL Errors(13436): GL ERRORS: 3085656
W/GL Errors(13436): GL ERRORS: 3085656
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 1286872464
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 772961407
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 55586330
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 229433297
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: 1984777172
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -760160237
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -1251139266
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0
W/GL TEXTURE NAME(13436): GL TEXTURE NAME: -24809019
W/Thread Name(13436): THREAD NAME: GLThread 28
W/GL Errors(13436): GL ERRORS: 0
W/GL Errors(13436): GL ERRORS: 0

Notice that CCTexture2D.loadTexture() is being called by 3 different threads. Each time it's called from a thread that isn't the GL Context, opengl is throwing errors. I am almost certain that this is the issue.

Also note that in this case, thread 28 is a SensorManager thread:

 28 13466   native  133 472 android.hardware.SensorManager$SensorThread 

and thread 29 is a worker thread that I have running in a ThreadPool for loading resources in the background:

29  13465   wait    0   0   pool-1-thread-1 

I don't know what the solution for this is, but I guess for now I'm just going to make a crude check to ensure that the current thread is the GL thread, and if not, just return. It's not elegant, but maybe it will work?

I hope to be back with more later.

dustinanon commented 13 years ago

Well shit. Scratch that.

W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 100271
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 315638026
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 534244737
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 1505553220
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -1563003837
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -867317458
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -1700480907
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -2028555960
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 1841779351
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -1054071278
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -1422854359
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -1408567796
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 1363318443
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 1671093174
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -553484899
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 1286872464
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 772961407
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 55586330
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 229433297
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 1984777172
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -760160237
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -1251139266
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -24809019
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 1995859160
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: -1369731737
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 622950690
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0
W/GL TEXTURE NAME(13594): GL TEXTURE NAME: 639059833
W/Thread Name(13594): THREAD NAME: GLThread 28
W/GL Errors(13594): GL ERRORS: 0
W/GL Errors(13594): GL ERRORS: 0

Everything was called only from the GLThread and still white textures... back to the drawing board.

dustinanon commented 13 years ago

Okay, maybe it still is the problem. I think what the issue is, is that you have a race condition in GLResourceHelper.perform(GLResorceTask res)

In the perform method, you only check to see that inUpdate is true before attempting to execute the task.

Suppose that the GLThread calls GLResourceTask.setInUpdate(true) and begins updating. Then another thread comes along and tries to create a texture during the update cycle.

GLResourceTask.perform() is called by the second thread, and it checks that inUpdate is true. Sure enough it is, so the second thread goes ahead and tries to perform the task. OpenGL then fails due to the incorrect context, and processes continue as normal because no exception is raised by OpenGL.

It's my belief that this is the problem behind this whole white textures ordeal.

cmaurer68 commented 12 years ago

Hi,

I have been following this issue as I have experienced a very similar issue on my end. I had submitted it on the google project page. http://code.google.com/p/cocos2d-android-1/issues/detail?id=97. I am wondering whether this is still being supported or if anyone has any advice?

This issue is a deal breaker for me using the library if it cannot be resolved. I wanted cocos2d to be a nice easy port from iphone, but it has been a much bigger project than I anticipated. I very much want to be able to use the cocos2d library for Android too.

If the project is not being supported, can anyone suggest an openGL library for android?

irwinb commented 12 years ago

Have a look at libGDX. Excellent set of tools.

gwennguihal commented 12 years ago

I have the same problem. I'm trying to load my textures in an AsyncTask to display a loader.

[code] IAsyncCallback callback = new IAsyncCallback() {

        @Override
        public void workToDo()
        {
            // load textures
            CCTextureCache.sharedTextureCache().addImage("background.png");
            CCTextureCache.sharedTextureCache().addImage("splashscreen.png");

            C.trace("load...");
        }

        @Override
        public void onComplete()
        {
            C.trace("load complete");
            GameManager.sharedGameManager().changeScene(Constants.SCENE_HOME);
        }

    };

    new AsyncTaskLoader().execute(callback);

[/code]

billy1380 commented 12 years ago

Apologies for posting on a "dormant" thread, but, hopefully this might help someone. I used code that looks like this:

GLResourceHelper.sharedHelper().perform(new GLResourceHelper.GLResorceTask() { @Override public void perform(GL10 gl) { // do something here } });

This did not sort the problem because the helper checks a variable "inUpdate" and if it is set to true then it will attempt to process the task straight away... there is no guarantee however that the call is being made for the correct thread or that the value of inUpdate can be relied upon... so I changed the code to always add the task to the task list and wait for the update loop which will process it and any others.

That seemed to sort my problem, no more white textures.

I also removed "setInUpdate" and removed all calls to the method made from CCDirector.