Reputation: 75
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);
}});
Upvotes: 1
Views: 5008
Reputation: 10106
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/
Upvotes: 2