Android Question libGDX: ScreenManger Pause/Resume

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I'm working on a game app with a few screens, each screen is made and handled in its own events.

I'm getting odd behavior when my app looses focus (e.g. home button, call, text, etc.). The events seem to be firing in the correct order:
B4X:
GameScreen_SHOW
** Activity (main) Pause, UserClosed = false **
ACTIVITY_PAUSE
sensor listener tear down
GameScreen_PAUSE
paused
** Activity (main) Resume **
ACTIVITY_RESUME
sensor listener setup
framebuffer: (5, 6, 5, 0)
depthbuffer: (24)
stencilbuffer: (8)
samples: (0)
coverage sampling: (false)
Managed meshes/app: { 1 }
Managed textures/app: { 8 }
Managed shaders/app: { 1 }
Managed buffers/app: { }
GameScreen_RESUME
resumed
but when you switch back there are no background graphics being rendered (see attached images). You can still interact with the UI to return to a previous screen (menu) and then go back to the game screen but from that point forward the background textures are black or display some other random part of the atlas.

The backgrounds are lgTexture objects initialized with pixmap from my asset manager then the texture is used to create a lgScn2DTextureRegionDrawable object that is set to the background of a lgscn2DTable in the scene.

Should I need to dispose and re-create the background textures in the pause/resume events for the screen?
 

Attachments

  • before_home.png
    before_home.png
    172.3 KB · Views: 442
  • after_home_key.png
    after_home_key.png
    21.8 KB · Views: 494

Informatix

Expert
Licensed User
Longtime User
I'm working on a game app with a few screens, each screen is made and handled in its own events.

I'm getting odd behavior when my app looses focus (e.g. home button, call, text, etc.). The events seem to be firing in the correct order:
B4X:
GameScreen_SHOW
** Activity (main) Pause, UserClosed = false **
ACTIVITY_PAUSE
sensor listener tear down
GameScreen_PAUSE
paused
** Activity (main) Resume **
ACTIVITY_RESUME
sensor listener setup
framebuffer: (5, 6, 5, 0)
depthbuffer: (24)
stencilbuffer: (8)
samples: (0)
coverage sampling: (false)
Managed meshes/app: { 1 }
Managed textures/app: { 8 }
Managed shaders/app: { 1 }
Managed buffers/app: { }
GameScreen_RESUME
resumed
but when you switch back there are no background graphics being rendered (see attached images). You can still interact with the UI to return to a previous screen (menu) and then go back to the game screen but from that point forward the background textures are black or display some other random part of the atlas.

The backgrounds are lgTexture objects initialized with pixmap from my asset manager then the texture is used to create a lgScn2DTextureRegionDrawable object that is set to the background of a lgscn2DTable in the scene.

Should I need to dispose and re-create the background textures in the pause/resume events for the screen?
The OpenGL context is lost after a Pause/Resume (it's not related to libGDX or B4A). The managed resources (e.g. the textures loaded by the asset manager) are reloaded automatically, but that's not the case of the textures that you created yourself by code. So you have to reload/recreate them in your Resume event before drawing.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I suspected something like that as some items were unaffected while others were "lost." I just didn't see a connection between them.

This may be a salient point to put in your tutorial documentation under the "libGDX Lifecycle" section where you're describing the pause and resume events.

Thank you once again for coming to my rescue! :oops:
 
Upvote 0
Top