views:

99

answers:

1

I am writing code that will allow the user to browse through the files on their SD card to locate images and them load them using openGL ES 2.0. This works fine when I had used just an EditText to type in the file path, but now that I have implemented a file browser that makes the exact same call with a String of the file path I get "Call to openGL API without a current context" in the LogCat.

I assumed this had something to do with the loader activity being over top the GLSurfaceView so I set up that activity terminates before any of the openGL calls were ever made, but no dice.

What gives?

Here are some code snippets:

Called when the user has clicked a file within the loader

    public void backOut(String filePath) {
        // inform the main Activity of the file to load...
        Intent i = new Intent();
        i.putExtra("filePath", filePath);

        setResult(Activity.RESULT_OK, i);
        // ... and end the load activity
        finish();
    }

Inside the main Activity, which holds the GLSurfaceView

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) {     
  super.onActivityResult(requestCode, resultCode, data); 
  switch(requestCode) { 
    case (1) : { 
      if (resultCode == Activity.RESULT_OK) { 
      String toLoad = data.getStringExtra("filePath");
      Log.v(TAG, toLoad);
      gl.informRendererLoadTexture(toLoad);
      } 
      break; 
    } 
  } 
}

And in the GLSurfaceView

 public void informRendererLoadTexture(String filePath){
     _filePath = filePath;
     queueEvent(new Runnable(){
            public void run() {
                _renderer.loadGLTexture(_filePath);
            }});
+1  A: 

From the GLSurfaceView documentation:

"There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with that context will be automatically deleted. In order to keep rendering correctly, a renderer must recreate any lost resources that it still needs. The onSurfaceCreated(GL10, EGLConfig) method is a convenient place to do this."

You need to be aware of lost OpenGL contexts, then reacquire the context and reload all OpenGL resources. It looks like your context is being lost when you display the full-screen file browser.

You can check out Replica Island's for sample code on detecting and handling lost contexts: http://code.google.com/p/replicaisland/

Julio Gorgé
Thank you for the response, I have been looking all over for an example of this. I am currently wading through the abundance of information provided but I am still a little unsure as to why my code doesn't work.I made especially sure to wait until after returning to the Activity that holds my GLSurfaceView to make any openGL calls to ensure that the context would be in place.Could you perhaps provide me with a small example? I don't care about losing textures or anything like that, just making sure to make the call to load the new texture after the context is in place again.
Frank
Digging through the code took a little time, but thank you. This lead me to a solution.
Frank
Glad you got it working. Unfortunately I didn't have an isolated code sample that I could share with you.
Julio Gorgé