Yalantis / StarWars.Android

This component implements transition animation to crumble view into tiny pieces.
https://yalantis.com/blog/star-wars-the-force-awakens-or-how-to-crumble-view-into-tiny-pieces-on-android/
MIT License
1.95k stars 303 forks source link

Fatal Exception: Error loading texture #3

Open ParkSangGwon opened 8 years ago

ParkSangGwon commented 8 years ago

I got error report from this library. how can I fix or check code? is this bug? I thik this error is not appear all time. some device occur error

Fatal Exception: java.lang.RuntimeException: Error loading texture. at com.yalantis.starwars.utils.gl.TextureHelper.loadTexture(TextureHelper.java:53) at com.yalantis.starwars.render.StarWarsRenderer$2.run(StarWarsRenderer.java:290) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1471) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)

defHLT commented 8 years ago

It occurs when texture can't be generated because of a trashed OpenGL context. One way it can happen when mTilesFrameLayout.startAnimation() is called after mTilesFrameLayout.onPause(). Do you work on your own example? If so please check your onResume/onPause calls or share your code if problem persists. If you're getting this error when running provided demo sample then please share more detailed steps and I'll try to reproduce it.

ParkSangGwon commented 8 years ago

ok. I will add some code. when mTilesFrameLayout.startAnimation() is called, I will check mTilesFrameLayout's state ( already onPause() or not )

and I will add try/catch block like this

        if(tiles_frame!=null){

            try {
                tiles_frame.startAnimation();
            }catch(Exception e){
                finish();
                overridePendingTransition(0, 0);
            }

        }
bradmartin commented 8 years ago

I'm working on taking this library and integrating a plugin for NativeScript and I get the same error when I call .startAnimation() on the instance of TilesFrameLayout view. The app isn't pausing so it's likely some app life cycle that NativeScript implements just not certain. I load the view and then on a click (tap) event I get a reference to the view and call .startAnimation() so I'm not sure about onPause() being called.

defHLT commented 8 years ago

@bradmartin the only was I can reproduce it if I comment out mTilesFrameLayout.onResume(); call in demo app and then go from and back to activity. That would cause GL thread to pause and texture loading would throw an error unless thread will be resumed before that. Can't think of another reason for this crash right now. Could you debug and ensue onResume call is really happening in right time?

defHLT commented 8 years ago

@bradmartin the only way I can reproduce it if I comment out mTilesFrameLayout.onResume(); call in demo app and then go from and back to activity. That would cause GL thread to pause and texture loading would throw an error unless thread will be resumed before that. Can't think of another reason for this crash right now. Could you debug and ensue onResume call is really happening in right time?

bradmartin commented 8 years ago

@mlatu - I've called onResume() and everything seems fine. Can any view be in the layout? I think the bitmap is not being passed correctly to the TextureHelper which is where the RunTimeException is thrown (line 53).

defHLT commented 8 years ago

@bradmartin Yes, any view can be in the layout. If there are several views - just wrap it in any ViewGroup.

Exception at line 53 is thrown if glGenTextures failed to do its job. It usually happens when there is no OpenGL context available. At this point it never even tries to work with the bitmap because glGenTextures fails. Could you call

int err = GLES20.glGetError();
String msg = GLUtils.getEGLErrorString(err);

just before the throw (after glGenTextures) and see what's the results?

I would do that but I don't have your setup

bradmartin commented 8 years ago

Working on adding this, android/java are not my specialites so I'm having a time including a forked repo into my project. If I knew the correct way to create a .jar file for this library then I could figure it out but for some reason my .jar files I generate aren't working correctly.

TeeRawk commented 7 years ago

Hello @bradmartin ,so does this worked for you ?