Android life cycle + “release(): something's wrong here, releasing unknown texture id”

Hello all,

I developed a new mechanism to control life cycle events in OF android.

The two big issues I came to solve are:

  1. Separation of app scope initialization from activity scope initialization: the first activity doesn’t need to be OFActivity, it can be plane ol’ Android activity and the native part can still get initialized and used.
  2. Ability to destroy the OFActivity while keeping the process alive. Current OF destroys everything when the OFActivity is destroyed and the app can’t continue to run.

I have a working version that does (1) but I have a bug in (2) that I can’t find and I’d be thrilled if an Android guru or two can find some time to have a look!

The version is in my github fork, I merged the latest master into it: https://github.com/tallavi/openFrameworks/tree/life_cycle_updated

I modified examples/android/androidEmptyExample to show the issue. It’s a simple app that loads a single ofImage and draws it.

Here are some excerpts from the log.

  1. When the app loads, everything is as usual, no errors.

  2. When the app is minimized, the ofApp indeed pauses as requested, but there’s one error (which is not new to this branch but may be related):

    07-13 15:19:29.384: I/OFAndroidLifeCycleHelper(7775): onPause
    07-13 15:19:29.494: I/ofAppAndroidWindow(7775): onSurfaceDestroyed
    ====> 07-13 15:19:29.494: E/libEGL(7775): call to OpenGL ES API with no current context (logged once per thread)

I don’t know where it comes from or what causes it.

  1. When the app resumes, everything is normal. I want to note that I had issues with resuming Android apps, causing black rectangles on the native android UI (link to the old post: Android - unload/reloading textures result in black rectangles instead of text). Among other advantages, this branch resolves this bug by fixing the resuming process. This bug was one of the reasons that began this long quest to solve the life cycle issues.

  2. Now for the interesting part. When I press back to actually destroy the activity, it destroys it successfully without killing the process. This is new to this branch:

    07-13 15:23:18.934: I/OFAndroidLifeCycleHelper(7775): onPause
    07-13 15:23:19.084: I/ofAppAndroidWindow(7775): onSurfaceDestroyed
    07-13 15:23:19.124: I/OFAndroidLifeCycleHelper(7775): onDestroy

  3. But, when I reactivate the app and try to recreate the activity in the same process, I get this:

    07-13 15:24:18.324: I/OF(7775): OFAndroid init…
    07-13 15:24:18.324: V/OF(7775): trying to find class: cc.openframeworks.androidEmptyExample.R$layout
    ====> 07-13 15:24:18.434: E/(7775): setup gles1
    07-13 15:24:18.444: I/ofApp(7775): CTOR
    07-13 15:24:18.444: I/OFAndroidLifeCycleHelper(7775): onResume
    07-13 15:24:18.494: I/OF(7775): onSurfaceCreated
    07-13 15:24:18.494: I/ofAppAndroidWindow(7775): onSurfaceCreated
    ====> 07-13 15:24:18.494: E/ofTexture(7775): release(): something’s wrong here, releasing unknown texture id 1049007697
    07-13 15:24:18.494: I/ofAppAndroidWindow(7775): setup
    07-13 15:24:18.494: I/BUG(7775): setup start
    07-13 15:24:18.514: I/BUG(7775): setup end

There are two errors. The first one I get is that gles1 is used. I don’t know why it’s an error, but it only happens on second init, so it must be a clue, right?

Also, I get that an unknown texture was released. I don’t release anything on setup. I only create one new image. It actually happens BEFORE setup() runs. I guess that something is wrong with the automatic mechanism that registers to unloadGl and reloadGl and automatically releases and reacquire the texture, but I don’t know what!

  1. Now, if I try to press back again, I get this again, but now I get it:

07-13 15:27:22.184: E/libEGL(7775): call to OpenGL ES API with no current context (logged once per thread)

  1. And finally, if I create the activity the THIRD time, nothing works:

    07-13 15:28:10.224: I/OF(7775): OFAndroid init…
    07-13 15:28:10.234: V/OF(7775): trying to find class: cc.openframeworks.androidEmptyExample.R$layout
    ====> 07-13 15:28:10.254: E/(7775): setup gles1
    07-13 15:28:10.254: I/ofApp(7775): CTOR
    07-13 15:28:10.254: I/OFAndroidLifeCycleHelper(7775): onResume
    07-13 15:28:10.314: I/OF(7775): onSurfaceCreated
    07-13 15:28:10.314: I/ofAppAndroidWindow(7775): onSurfaceCreated
    07-13 15:28:10.314: I/ofAppAndroidWindow(7775): setup
    07-13 15:28:10.314: I/BUG(7775): setup start
    ====> 07-13 15:28:10.324: E/ofImage(7775): loadImage(): couldn’t load image from “white.png”
    07-13 15:28:10.324: I/BUG(7775): setup end
    07-13 15:28:10.324: I/ofAppAndroidWindow(7775): resize 1080x1587
    07-13 15:28:10.324: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.334: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.344: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.354: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.364: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.384: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.394: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.414: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.434: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.444: W/ofGLRenderer(7775): drawing an unallocated texture
    07-13 15:28:10.464: W/ofGLRenderer(7775): drawing an unallocated texture

For some reason, it can’t load the image anymore.

Sorry for the lengthly post, but I wanted to give the exact reproduction and logs to describe the issue as best as I can…

I verified that everything completely works as long as I don’t use ofImage/ofTexture. The problem is definitely in that area.

I would LOVE to solve this last issue, clean it up and suggest a PR already!

Thanks!

Tal

Hi @tallavi

I am also facing a similar issue. When the activity is created for the third time. Nothing works.
Did you get a resolution ?
Any suggestions on how to proceed for analysis .

HI @Akash,

In which branch did you get this?

This was resolved a long time ago in this PR https://github.com/openframeworks/openFrameworks/pull/4260 and it’s included in 0.9.*.

I’m working on a variant of 0.9.3 and I don’t have it anymore.

Usually this is caused by not handling reloadTextures() event. When you get this event (usually when the android app is going to background and then resuming) - you should reload all the textures as they are become invalid.

Thanks for the reply @tallavi
I am using version 0.9.8.

Error shown is :-

       E/ofImage: loadImage(): couldn't load image from "/storage/emulated/0/input1484751507295.png"

       [ 01-18 20:28:34.256 18837:19504 E/         ]
       ofPixels: format doesn't support channels

       E/cv::error(): OpenCV Error: Assertion failed (ssize.area() > 0) in void cv::resize(cv::InputArray, cv::OutputArray, cv::Size, double, double, int), file /home/arturo/Code/openFrameworks/scripts/apothecary/build/opencv/modules/imgproc/src/imgwarp.cpp, line 1834

       A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 19504 (GLThread 31406)  
       A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x758e21a6 in tid 20975 (GLThread 29658) 

Could not understand why getting this error in the version. Any suggestions ?

Hmm, I don’t see the unknown texture id problem anywhere in your message.

It seems that the problem is different - that input1484751507295.png is in a format which is not supported. Is it a file you provided? Or is it auto generated by something?

I never used openCV, so I don’t know if it’s a known issue or not.