ofBackgroundGradient causes application crashes

In my application I would like to use ofBackgroundGradient (we use it in the iOS version of the app). However when I use ofBackgroundGradient it causes the app to crash. The app runs fine when starting up. Yet whenever the app is started after it has been stopped (i.e. switching to another app and then switching back) it crashes.

In order to test this I modified the AndroidTouchExample. The only modification I made to the example was to add the example ofBackgroundGradient code (from the documentation) to the draw function. Resulting in the following draw function:

void ofApp::draw() {
    ofColor colorOne;
    ofColor colorTwo;

    colorOne.set (255, 0, 0);
    colorTwo.set (0, 0, 255);

    ofBackgroundGradient(colorOne, colorTwo, OF_GRADIENT_CIRCULAR);
    for(int i=0; i<NUM_POINTS; i++) balls[i].draw();
}

I have done some debugging and here is the LogCat output for running the modified AndroidTouchExample.

08-26 11:21:59.001: I/OF(12185): onPause
08-26 11:21:59.113: I/ofAppAndroidWindow(12185): onSurfaceDestroyed
08-26 11:21:59.779: I/OF(12185): OFAndroid init...
08-26 11:21:59.779: V/OF(12185): trying to find class: cc.openframeworks.androidTouchExample.R$layout
08-26 11:21:59.811: I/OF(12185): onResume
08-26 11:21:59.812: I/OF(12185): resume view and native
08-26 11:21:59.812: I/ofAppAndroidWindow(12185): onResume
08-26 11:21:59.892: I/OF(12185): onSurfaceCreated
08-26 11:21:59.892: I/ofAppAndroidWindow(12185): onSurfaceCreated
08-26 11:21:59.892: E/Adreno-ES11(12185): <qglDrvAPI_glGetString:619>: GL_INVALID_ENUM
08-26 11:21:59.893: W/ofVbo(12185): release(): something's wrong here, releasing unkown vertex buffer object id 1074471384
08-26 11:21:59.893: W/ofVbo(12185): release(): something's wrong here, releasing unkown vertex buffer object id 1150550016
08-26 11:21:59.893: W/ofVbo(12185): release(): something's wrong here, releasing unkown vertex buffer object id 2
08-26 11:21:59.894: A/libc(12185): Fatal signal 11 (SIGSEGV) at 0x0000000f (code=1), thread 12245 (Thread-616)

From looking into the errors I think the error has to do with openGL running in the wrong thread causing a segfault. However I do not know how to fix this.

Is there something I am doing wrong? Or is this a bug with openFrameworks?

Maybe someone can give a more correct answer. Anyway, what I think after seeing your log is, you should add a function to the ofGraphics.cpp:

ofVboMesh ofGetGradientBackground() {
    return gradientMesh;
}

Then you should write the code below inside the “pause()” method of your ofApp.cpp:

void ofApp::pause() {
    ofGetGradientBackground().clear();
}

And then you should write the code below inside the “reloadTextures()” method of your ofApp.cpp:

void ofApp::reloadTextures() {
    ofBackgroundGradient(colorOne, colorTwo, OF_GRADIENT_CIRCULAR);
}

Please note that this may be wrong. And I can not test it, I wrote it directly on web. But something similar would be the first thing I would try in your case.

Thanks for the idea, unfortunately it didn’t seem to work. I got the same behavior as before.

I have done some more debugging and I discovered that the app crashes when onSurfaceCreated is called. Specifically it crashes when onSurfaceCreated calls ofReloadGLResources. Yet I haven’t been able to find the implementation of this function anywhere.