Strange looking preference activity in livewallpaper

Started by kkl, May 28, 2013, 04:45:58 AM

Previous topic - Next topic

kkl

Hi,

Does anyone have the strange looking preference activity in android before? The fonts in preference activity becomes square after some settings have been made there.

Step to reproduce:
1. Load texture and add objects to world
2. In preference activity, if the feature is unchecked by user, unload texture immediately and remove objects from world.
3. Go back to livewallpaper preview.
4. Goto the preference activity again. It shows square font (font is in english, no other language), and no errors from JPCT-AE log.

However, if I don't unload the texture and only remove objects from world, it doesn't cause the error.

[attachment deleted by admin]

EgonOlsen

Looks like as if the textures of the font get unloaded, which can only be caused if the unloading happens in the wrong gl context. Honestly, i don't see how this should be possible. I assume that Config.unloadImmediately has been set to true? Does this happen on all devices? It might be a driver bug as well...

kkl

I never expect that happen too. Yes, Config.unloadImmediately is set to true. I tried it on S2, nexus 4 and nexus 7, all have the same weird looking preference activity after the steps are reproduced (nexus 4 and nexus 7 show broken texture at the preference activity group titles respectively). Judging from what you said, i started to think it can be possible as I share the texture for both livewallpapers from home screen and preview. It happens when I disable a feature from preview, and the preview tries to unload the texture from livewallpaper home screen; different gl context.

Egon, what would you suggest? Is it possible to unload texture with finding back the correct gl context? (I tried dispose everything when onPause() is called and reload all textures and objects during onResume(), but it takes a long time to reload everything back which causes my livewallpaper a big lag at the beginning)

EgonOlsen

If you are unloading the texture in anything but the onDraw()-method, it happens in another thread and nobody knows which context is active then. There's nothing i can do about it and the only solution is not to do it. Why are you unloading the textures anyway? The native resources that they are using should be freed once the context is lost.

kkl

I have a feature in which it changes texture based on user's preference. The textures are huge and it may cause memory error if I load all of them. So, I load the texture that is needed and unload the one that is not needed.

kkl

Hi Egon,

I tried by just having livewallpaper preview without setting it to the phone, and unloading texture still causes error. I checked from jPCT-ae log, it says opengl context has changed.


05-29 16:50:15.218: I/jPCT-AE(6647): Visibility lists disposed!
05-29 16:50:15.218: I/jPCT-AE(6647): All texture data unloaded from gpu!
05-29 16:50:15.218: I/jPCT-AE(6647): Disposing VBOs!
05-29 16:50:15.223: I/jPCT-AE(6647): Renderer disposed!
05-29 16:50:15.228: I/jPCT-AE(6647): OpenGL vendor:     ARM
05-29 16:50:15.228: I/jPCT-AE(6647): OpenGL renderer:   Mali-400 MP
05-29 16:50:15.228: I/jPCT-AE(6647): OpenGL version:    OpenGL ES-CM 1.1
05-29 16:50:15.228: I/jPCT-AE(6647): OpenGL renderer initialized (using 2 texture stages)
05-29 16:50:15.228: I/jPCT-AE(6647): OpenGL context has changed(2)...recovering for renderer 14/13!


It also says all textures unloaded from GPU while I din't flush the TextureManger explicitly. May I know what is happening there and why the gl context changed when it resumes to the same livewallpaper preview? (The log pops up when I goto preference activity and come back to the preview)

EgonOlsen

If you create a new framebuffer, it will consider this as a context change. If you can make sure that the context hasn't changed, don't create a new framebuffer.

EgonOlsen

Could you please set the Logger to debug and post the output after some context changes?

kkl

These are the logs in debug level after closing preference activity and resuming to preview:


05-29 19:47:42.610: I/jPCT-AE(13608): Unloaded texture: 3
05-29 19:47:42.630: I/jPCT-AE(13608): Visibility lists disposed!
05-29 19:47:42.630: I/jPCT-AE(13608): Unloaded texture: 6
05-29 19:47:42.630: I/jPCT-AE(13608): Unloaded texture: 4
05-29 19:47:42.630: I/jPCT-AE(13608): Unloaded texture: 2
05-29 19:47:42.630: I/jPCT-AE(13608): Unloaded texture: 1
05-29 19:47:42.630: I/jPCT-AE(13608): Unloaded texture: 5
05-29 19:47:42.630: I/jPCT-AE(13608): All texture data unloaded from gpu!
05-29 19:47:42.630: I/jPCT-AE(13608): Disposing VBOs!
05-29 19:47:42.640: I/jPCT-AE(13608): Renderer disposed!
05-29 19:47:42.640: I/jPCT-AE(13608): GLRenderer disposed with id 1 on Thread[GLThread 55676,5,main]
05-29 19:47:42.640: I/jPCT-AE(13608): GLRenderer created with id 2 on Thread[GLThread 55676,5,main]
05-29 19:47:42.645: I/jPCT-AE(13608): OpenGL vendor:     ARM
05-29 19:47:42.645: I/jPCT-AE(13608): OpenGL renderer:   Mali-400 MP
05-29 19:47:42.645: I/jPCT-AE(13608): OpenGL version:    OpenGL ES-CM 1.1
05-29 19:47:42.645: I/jPCT-AE(13608): OpenGL renderer initialized (using 2 texture stages)
05-29 19:47:42.645: I/jPCT-AE(13608): Allocating native memory for 128*128 texture(true/false/false/false/): 65536 bytes!
05-29 19:47:42.650: I/jPCT-AE(13608): New texture's id is: 1
05-29 19:47:42.650: I/jPCT-AE(13608): New texture uploaded: com.threed.jpct.Texture@41f82c48 in thread Thread[GLThread 55676,5,main]
05-29 19:47:42.650: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:42.650: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:42.650: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:42.650: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:42.650: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:42.650: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:42.650: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:42.650: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:42.650: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:42.650: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:42.655: I/jPCT-AE(13608): Allocating native memory for 1024*1024 texture(true/false/false/false/): 4194304 bytes!
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly1'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly2'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly3'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly4'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly5'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly6'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly7'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly8'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly9'
05-29 19:47:42.905: I/jPCT-AE(13608): VBO disposed for object 'firefly10'
05-29 19:47:42.920: I/jPCT-AE(13608): New texture's id is: 2
05-29 19:47:42.940: I/jPCT-AE(13608): New texture uploaded: com.threed.jpct.Texture@41f82fa8 in thread Thread[GLThread 55676,5,main]
05-29 19:47:42.940: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:42.940: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:42.940: I/jPCT-AE(13608): Allocating native memory for 1024*1024 texture(true/false/false/false/): 4194304 bytes!
05-29 19:47:43.165: I/jPCT-AE(13608): New texture's id is: 4
05-29 19:47:43.175: I/jPCT-AE(13608): New texture uploaded: com.threed.jpct.Texture@41f71e68 in thread Thread[GLThread 55676,5,main]
05-29 19:47:43.175: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.175: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.175: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.175: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.175: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.175: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.175: I/jPCT-AE(13608): Allocating native memory for 64*64 texture(true/false/false/false/): 16384 bytes!
05-29 19:47:43.175: I/jPCT-AE(13608): New texture's id is: 5
05-29 19:47:43.175: I/jPCT-AE(13608): New texture uploaded: com.threed.jpct.Texture@41f76910 in thread Thread[GLThread 55676,5,main]
05-29 19:47:43.175: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.175: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.180: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.180: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.180: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.180: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.180: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.180: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.180: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.180: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.180: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.180: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.180: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.180: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.180: I/jPCT-AE(13608): Allocating native memory for 64*64 texture(true/false/false/false/): 16384 bytes!
05-29 19:47:43.185: I/jPCT-AE(13608): New texture's id is: 6
05-29 19:47:43.185: I/jPCT-AE(13608): New texture uploaded: com.threed.jpct.Texture@41f6db30 in thread Thread[GLThread 55676,5,main]
05-29 19:47:43.185: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.185: I/jPCT-AE(13608): Creating buffers...
05-29 19:47:43.185: I/jPCT-AE(13608): OpenGL context has changed(2)...recovering for renderer 2/1!
05-29 19:47:43.185: I/jPCT-AE(13608): Creating buffers...


I also tried without creating the new framebuffer when context changes. The same issue is still there. Surprisingly, I do exactly the same method to other objects and textures, it works fine.

EgonOlsen

Looks fine to me. You are obviously disposing the framebuffer and creating a new one in the same thread...when does this happen and why? I'm still not sure about what exactly you are doing...

You have a preview activity, you pause and open the preferences, you close the preferences and resume the preview activity? At which stage are you disposing the framebuffer? Before or after pausing the preview activity?

kkl

I dispose the framebuffer after pausing the preview. To be exact, it's resuming the preview.

This is the flow where I dispose the framebuffer in a nutshell.

onPause() -> (Goto Preference activity) -> (Quit preference activity) -> onResume() -> onSurfaceChanged() -> (dispose framebuffer)

Does disposing the framebuffer change the gl context and affect on unloading textures?


EgonOlsen

Disposing the buffer unloads textures, but it doesn't do anything to the context. Try to dispose the framebuffer before opening the preferences, i.e. somewhere in onPause() and see what that does...

kkl

Wow.. Disposing frame buffer on onPause() fixed the problem. No more square font so far. What is exactly happening there?

The logs on onPause():

05-30 18:35:33.138: I/jPCT-AE(6570): Visibility lists disposed!
05-30 18:35:33.138: I/jPCT-AE(6570): Unloaded texture: 38
05-30 18:35:33.138: I/jPCT-AE(6570): Unloaded texture: 36
05-30 18:35:33.138: I/jPCT-AE(6570): Unloaded texture: 35
05-30 18:35:33.138: I/jPCT-AE(6570): Unloaded texture: 33
05-30 18:35:33.138: I/jPCT-AE(6570): Unloaded texture: 37
05-30 18:35:33.138: I/jPCT-AE(6570): Unloaded texture: 34
05-30 18:35:33.138: I/jPCT-AE(6570): All texture data unloaded from gpu!
05-30 18:35:33.138: I/jPCT-AE(6570): Disposing VBOs!
05-30 18:35:33.138: I/jPCT-AE(6570): Renderer disposed!
05-30 18:35:33.138: I/jPCT-AE(6570): GLRenderer disposed with id 28 on Thread[main,5,main]
   

The logs on onResume():

05-30 18:35:46.048: I/jPCT-AE(6570): GLRenderer created with id 29 on Thread[GLThread 57759,5,main]
05-30 18:35:46.048: I/jPCT-AE(6570): OpenGL vendor:     ARM
05-30 18:35:46.053: I/jPCT-AE(6570): OpenGL renderer:   Mali-400 MP
05-30 18:35:46.053: I/jPCT-AE(6570): OpenGL version:    OpenGL ES-CM 1.1
05-30 18:35:46.053: I/jPCT-AE(6570): OpenGL renderer initialized (using 2 texture stages)
05-30 18:35:46.053: I/jPCT-AE(6570): Allocating native memory for 128*128 texture(true/false/false/false/): 65536 bytes!
05-30 18:35:46.053: I/jPCT-AE(6570): New texture's id is: 39
05-30 18:35:46.053: I/jPCT-AE(6570): New texture uploaded: com.threed.jpct.Texture@425b70c8 in thread Thread[GLThread 57759,5,main]
05-30 18:35:46.053: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.053: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.053: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.053: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.053: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.053: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.053: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.053: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.053: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.053: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.063: I/jPCT-AE(6570): Allocating native memory for 1024*1024 texture(true/false/false/false/): 4194304 bytes!
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly9'
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly1'
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly2'
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly3'
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly4'
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly5'
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly6'
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly7'
05-30 18:35:46.148: I/jPCT-AE(6570): VBO disposed for object 'firefly8'
05-30 18:35:46.153: I/jPCT-AE(6570): VBO disposed for object 'firefly10'
05-30 18:35:46.333: I/jPCT-AE(6570): New texture's id is: 40
05-30 18:35:46.378: I/jPCT-AE(6570): New texture uploaded: com.threed.jpct.Texture@4271bb30 in thread Thread[GLThread 57759,5,main]
05-30 18:35:46.378: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.378: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.378: I/jPCT-AE(6570): Allocating native memory for 1024*1024 texture(true/false/false/false/): 4194304 bytes!
05-30 18:35:46.543: I/jPCT-AE(6570): New texture's id is: 41
05-30 18:35:46.583: I/jPCT-AE(6570): New texture uploaded: com.threed.jpct.Texture@42720e70 in thread Thread[GLThread 57759,5,main]
05-30 18:35:46.583: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.583: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.583: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.583: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.583: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.583: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.583: I/jPCT-AE(6570): Allocating native memory for 64*64 texture(true/false/false/false/): 16384 bytes!
05-30 18:35:46.583: I/jPCT-AE(6570): New texture's id is: 42
05-30 18:35:46.583: I/jPCT-AE(6570): New texture uploaded: com.threed.jpct.Texture@420e63c0 in thread Thread[GLThread 57759,5,main]
05-30 18:35:46.583: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.583: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.583: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.583: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.583: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.583: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.583: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.583: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.588: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.588: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.588: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.588: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.588: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.588: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.588: I/jPCT-AE(6570): Allocating native memory for 64*64 texture(true/false/false/false/): 16384 bytes!
05-30 18:35:46.588: I/jPCT-AE(6570): New texture's id is: 43
05-30 18:35:46.588: I/jPCT-AE(6570): New texture uploaded: com.threed.jpct.Texture@421379c8 in thread Thread[GLThread 57759,5,main]
05-30 18:35:46.588: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.588: I/jPCT-AE(6570): Creating buffers...
05-30 18:35:46.588: I/jPCT-AE(6570): OpenGL context has changed(2)...recovering for renderer 29/28!
05-30 18:35:46.588: I/jPCT-AE(6570): Creating buffers...

EgonOlsen

#13
I'm not 100% sure. Textures in a context are identified by a driver generated id. Once an id becomes freed or invalid because of a context loss, the driver is free to give it to another texture (or other data on the gpu). If you call dispose() after the resume, you are freeing textures bound to ids that actually belong to the preferences dialog now. I'll update the documentation to dispose() to make clear that it should be called BEFORE the current context gets out of scope.

kkl

If I don't dispose the framebuffer, and use the old framebuffer after onResume(), the problem seems to be the same. Is there any way to update the driver id without disposing frame buffer? Coz disposing the frame buffer causes a slight lag on onResume().