Also related to: Texture unloading/reloading results in black rectangles
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:
- Take android empty example
- add a button with text to the layout xml
- in setup and in reloadTextures load an image and a texture, resize the image
- in unloadTextures, unload both texture and image.
- start app
- If it didn’t happen, minimize and restore again. Usually it happens on first time, but not always.
That’s it. Attached are:
- zip of source files to reproduce the issue. It’s just src and res folder since the entire project was to large to upload.
- image of how it looks before minimizing
- 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,
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?
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:
and this in unload:
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…
there is not an “unloadTextures()” method in the openFrameworks’ Android implementation. I think it is something youve added yourself 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:
I’m on the latest master branch.
well you discovered a method
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 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
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