Android - unload/reloading textures result in black rectangles instead of text

Also related to: Texture unloading/reloading results in black rectangles

Hi,

Description of the issue:

Text on native UI elements turns to black rectangles after minimizing and restoring. See attached screenshots. It’s directly related to loading/unloading textures in of, but I’m not sure how.
I’ve managed of creating a super simple reproduction based on “android empty example” that shows the problem!

Steps I used to create the reproduction:

  1. Take android empty example
  2. add a button with text to the layout xml
  3. in setup and in reloadTextures load an image and a texture, resize the image
  4. in unloadTextures, unload both texture and image.

Reproduction steps:

  1. start app
  2. minimize
  3. restore
  4. If it didn’t happen, minimize and restore again. Usually it happens on first time, but not always.

That’s it. Attached are:

  1. zip of source files to reproduce the issue. It’s just src and res folder since the entire project was to large to upload.
  2. image of how it looks before minimizing
  3. image of how it looks after resuming

I’ve tried adding all sorts of checks in ofLoadImage and clear method, but to no avail!

I’m reproducing this issue on latest master branch.

Thanks allot in advance,

Tal


BlackRectanglesBug.zip (9.1 KB)

I don’t have the ability of testing your issue on the emptyexample. But i put a button on our game and it works. The button font looks ok after resuming.

I try 10-12 pause/resume, still ok.

What happens if you invoke unloadTextures from pause?

ofApp::pause(){
    unloadTextures();
}

Hey @Rancs!

Thanks for trying it out! Calling unload from pause didn’t make any difference. I guess it’s because unload and pause are called (almost?) immediately one after the other, no?

My app also didn’t exhibit the issue all the time. I had to hunt down the exact circumstances. It seems to be related to doing this in reload:

ofLoadImage(myTexture,"white.png");
ofLoadImage(myImage, "white.png");
myImage.resize(50, 50);

and this in unload:

myTexture.clear();
myImage.clear();

But I’m not sure what exactly. Heck, it might even be related to the specific “white.png” texture I’m using…

Putting the lines and the png file in any ofAndroid project should do the trick.

BTW, have you seen the stack overflow link I included in the previous post, on someone who was stuck on the same scenario and the proposed solution?

I was hoping that someone here who knows OF internals might be able to translate this into what I or OF are doing wrong in this specific scenario. I wasn’t able to figure this out. Everything seems to be reloading correctly…

Thanks!

Tal

there is not an “unloadTextures()” method in the openFrameworks’ Android implementation. I think it is something youve added yourself :slight_smile: so, no call to unload… you should write the ofImage.clear() calls inside the pause() method (or invoke your unload method from pause).

Well, I see it is being called.

And also, look at ofAppAndroidWindow.cpp lines 428 and 441:

if(androidApp){
	androidApp->unloadTextures();
}

I’m on the latest master branch.

Tal

well you discovered a method :slight_smile:

Back to the issue, i test your code with writing ofimage.clear() lines inside pause() and it works.

What the possible reasons may be?

  • a possibility; unload is not invoked (but it is)

  • another possibility; your app may do 2-3 consecutive pause-resume cycles

  • another one; your white image may be corrupted (as you told)

  • a different try may be running the app within a different opengles version.

  • or testing it on a different device

that’s all what i can imagine.

It seems to not only be related to a single line of code, but to that complete scenario. Loading just the image or texture, or not resizing - worked for me on some occasions. It’s tricky, that’s why I attached the exact reproduction.

Right you are.

I put some logs on the life cycle methods and verified that I’m getting pause then unload then resume then reload - everything seems in order…

If that was the case, why do I need to minimize and resume in order to create the bug, I would have thought it would be corrupt on first load also… Besides, I verified that the texture is visible :slight_smile: It’s just a white square.

Is there a way to do that?

Reproduced successfully on 3 different devices: HTC M8, Samsung S3 and another cheap samsung.

I’m becoming desperate :frowning:

UPDATE: I have a working branch that fixes the issue, and more issues with android life cycle. I just have one last bug to solve revolving around destroying the OFActivity and recreating it without causing problems. The link to my branch if you want to check it out and all details on the remaining issue are here: Android life cycle + “release(): something's wrong here, releasing unknown texture id”

i think the life cycle issues are solved in master already, not recreating the OFActivity of course, but resources should be loading fine after pausing and resuming in master