Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the software SDL_Renderer on Android leads to GL errors & black screen when window resizes #3285

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: HG 2.0
Reported for operating system, platform: Linux, x86_64

Comments on the original bug report:

On 2019-06-17 03:05:38 +0000, Ellie wrote:

With the latest hg version of SDL2 as of today, using the software SDL_Renderer on Android leads to GL errors & black screen when window resizes. The resize can both becaused by entering/leaving side-by-side on newer Androids, or just changing the orientation with an app that uses "user" or "sensor" orientation modes.

Steps to reproduce:

  1. Set SDL_ANDROID_BLOCK_ON_PAUSE to 0
  2. Create a window and an SDL_Renderer with SDL_RENDERER_SOFTWARE
  3. Use SDL_CreateTexture and SDL_RenderCopy, and use it correctly such that when SDL_APP_WILLENTERBACKGROUND comes in you stop touching anything until there was SDL_APP_DIDENTERFOREGROUND

Expected result: works with all renderers on Android

Actual result: OpenGL works fine, but with the software renderer I'm suddenly seeing errors in logcat on resize and the app render surface either freezes or goes black and never recovers until the app is terminated & launched again

This is how the errors look like:

6-13 02:09:46.317 15784 15784 V SDL : onPause()
06-13 02:09:46.318 15784 15784 V SDL : nativePause()
06-13 02:09:46.318 15784 15784 E libEGL : call to OpenGL ES API with no current context (logged once per thread)
06-13 02:09:46.322 2242 3220 V WindowManager: Changing focus from Window{158e875 u0 com.example.myapp/org.kivy.android.PythonActivity} to null Callers=com.android.server.wm.WindowManagerService.setFocusedApp:2722 com.android.server.am.ActivityManagerService.setResumedActivityUncheckLocked:3250 com.android.server.am.ActivityStack.setResumedActivityLocked:2284 com.android.server.am.ActivityStack.resumeTopActivityInnerLocked:2599
06-13 02:09:46.322 2242 3220 D WindowManager: Input focus has changed to null
06-13 02:09:46.466 15784 15804 D GraphicBuffer: register, handle(0xea1c7d20) (w:1080 h:2160 s:1088 f:0x1 u:b00)
06-13 02:09:46.466 2568 3214 E TaskStackLayoutAlgorithm: Invalid task rect: taskRect=Rect(41, 41 - -40, 855) stackRect=Rect(41, 41 - -40, 1080) displayRect=Rect(0, 0 - 2160, 1080) windowRect=Rect(0, 0 - 1, 1080) taskStackBounds=Rect(41, 0 - -40, 1080)
06-13 02:09:46.479 15784 15784 V SDL : onWindowFocusChanged(): false
06-13 02:09:46.493 412 879 I SurfaceFlinger: EventThread Client Pid (2568) created
06-13 02:09:46.494 412 879 I SurfaceFlinger: EventThread Client Pid (2568) created
06-13 02:09:46.501 2242 2255 I WindowManager: Relayout Window{9061c06 u0 DockedStackDivider}: oldVis=4 newVis=0 focusMayChange = true
06-13 02:09:46.504 2568 2568 D Surface : Surface::allocateBuffers(this=0x7d503e2000)
06-13 02:09:46.504 2568 2887 D Surface : Surface::connect(this=0x7d503e2000,api=1)
06-13 02:09:46.504 412 446 I BufferQueueProducer: DockedStackDivider# 0 connect(P): api=1 producer=(2568:com.android.systemui) producerControlledByApp=true
06-13 02:09:46.506 15784 15820 I python : wobblog-debug: APP BACKGROUND EVENT.
06-13 02:09:46.506 15784 15820 I python : wobblog-debug: ANDROIND IN BACKGROUND. KEEPING RENDERERS AS PER CONFIG OPTION. (not recommended)
06-13 02:09:46.506 412 412 I BufferQueueConsumer: com.example.myapp/org.kivy.android.PythonActivity# 0 disconnect(C)
06-13 02:09:46.510 412 412 I BufferQueue: com.example.myapp/org.kivy.android.PythonActivity# 0 ~BufferQueueCore
06-13 02:09:46.621 2568 2887 D GraphicBuffer: register, handle(0x7d60d4f780) (w:1080 h:2160 s:1088 f:0x1 u:b00)
06-13 02:09:46.654 412 412 I BufferQueueConsumer: Background for - SurfaceView - com.example.myapp/org.kivy.android.PythonActivity# 0 setDefaultBufferSize: width=1006 height=1019
06-13 02:09:46.654 412 412 I BufferQueueConsumer: SurfaceView - com.example.myapp/org.kivy.android.PythonActivity# 0 setDefaultBufferSize: width=1006 height=1019
06-13 02:09:46.657 15784 15784 V SDL : surfaceChanged()
06-13 02:09:46.657 15784 15784 V SDL : pixel format RGB_565
06-13 02:09:46.657 2568 2568 D StatusBar: setSystemUiVisibility vis=708 mask=ffffffff oldVal=708 newVal=708 diff=0
06-13 02:09:46.658 15784 15784 V SDL : Window size: 1006x1019
06-13 02:09:46.658 15784 15784 V SDL : Device size: 2160x1080
06-13 02:09:46.675 2568 2568 D StatusBar: setSystemUiVisibility vis=708 mask=ffffffff oldVal=708 newVal=708 diff=0

06-13 02:09:48.949 407 434 I vendor.mediatek.hardware.power@1.1-impl: mtkPowerHint hint:15, data:10000
06-13 02:09:48.965 2242 2285 V WindowManager: Changing focus from Window{41fcc9c u0 com.android.settings/com.android.settings.SubSettings} to Window{158e875 u0 com.example.myapp/org.kivy.android.PythonActivity} Callers=com.android.server.wm.DisplayContent.layoutAndAssignWindowLayersIfNeeded:2294 com.android.server.wm.StackWindowController.positionChildAtTop:159 com.android.server.am.ActivityStack.insertTaskAtTop:2830 com.android.server.am.ActivityStack.moveToFront:865
06-13 02:09:48.967 2242 2285 D WindowManager: Input focus has changed to Window{158e875 u0 com.example.myapp/org.kivy.android.PythonActivity}
06-13 02:09:48.978 2242 2285 I WindowManager: Focus moving from Window{41fcc9c u0 com.android.settings/com.android.settings.SubSettings} to Window{158e875 u0 com.example.myapp/org.kivy.android.PythonActivity}
06-13 02:09:48.979 2568 2568 D StatusBar: setSystemUiVisibility vis=518 mask=ffffffff oldVal=2618 newVal=518 diff=2300
06-13 02:09:48.978 407 434 I vendor.mediatek.hardware.power@1.1-impl: mtkPowerHint hint:11, data:2000
06-13 02:09:48.983 2242 5043 V WindowManager: Set focused app to: AppWindowToken{7172867 token=Token{ca8dc49 ActivityRecord{c0e9250 u0 com.example.myapp/org.kivy.android.PythonActivity t835}}} old focus=AppWindowToken{87b9040 token=Token{e24fc3 ActivityRecord{2e41
06-13 02:09:48.987 15784 15784 V SDL : onWindowFocusChanged(): true
06-13 02:09:48.993 407 434 I vendor.mediatek.hardware.power@1.1-impl: notifyAppState pack:com.example.myapp, act:org.kivy.android.PythonActivity, pid:15784, state:1
06-13 02:09:49.001 15784 15784 V PythonActivity: onResume()
06-13 02:09:49.002 15784 15784 V SDL : onResume()
06-13 02:09:49.016 15784 15784 V SDL : nativeResume()
06-13 02:09:49.028 15784 15784 V PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = ViewRoot{77452f2 com.example.myapp/org.kivy.android.PythonActivity,ident = 0}, this = DecorView@82ac254[PythonActivity]
06-13 02:09:49.032 15784 15820 E libEGL : eglMakeCurrent:1069 error 3002 (EGL_BAD_ACCESS)
06-13 02:09:49.038 2242 2255 D IdleScreen: activityIdleScreen: android.app.ContextImpl@3a7873 mNotifyNeeded: false idleIntent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.myapp/org.kivy.android.PythonActivity (has extras) }
06-13 02:09:49.034 15784 15820 E libEGL : eglMakeCurrent:1069 error 3002 (EGL_BAD_ACCESS)
06-13 02:09:49.038 407 434 I vendor.mediatek.hardware.power@1.1-impl: mtkPowerHint hint:11, data:0
06-13 02:09:49.042 412 806 I BufferQueueProducer: com.android.settings/com.android.settings.SubSettings# 0 queueBuffer: fps=3.31 dur=1508.35 max=1354.34 min=16.17
06-13 02:09:49.044 15784 15820 I python : wobblog-debug: APP RESUME EVENT
06-13 02:09:50.452 15784 15820 E libEGL : eglMakeCurrent:1069 error 3002 (EGL_BAD_ACCESS)
06-13 02:09:50.452 15784 15820 E libEGL : eglMakeCurrent:1069 error 3002 (EGL_BAD_ACCESS)
06-13 02:09:50.496 15784 15820 E libEGL : eglMakeCurrent:1069 error 3002 (EGL_BAD_ACCESS)
06-13 02:09:50.541 15784 15820 I chatty : uid=10150(com.example.myapp) SDLThread identical 2 lines
06-13 02:09:50.541 15784 15820 E libEGL : eglMakeCurrent:1069 error 3002 (EGL_BAD_ACCESS)

On 2019-06-17 15:41:07 +0000, Sam Lantinga wrote:

Sylvain, can you look at this for SDL 2.0.10 release?

Thanks!

On 2019-06-17 19:02:19 +0000, Sylvain wrote:

May be a duplicate of bug 3628. I mean this has existed for a while.

I think what happening with the software renderer is:

  • you're somehow in background (so texture creation is not possible)
  • it resizes and wants to push a SDL_WINDOWEVENT_SIZE_CHANGED
    It call:
    https://hg.libsdl.org/SDL/file/45b56ed51919/src/render/SDL_render.c#l683
  • GetOutputSize
  • SW_GetOutputSize
  • SW_ActivateRenderer
  • SDL_GetWindowSurface
  • SDL_CreateWindowFramebuffer which is mapped to SDL_CreateWindowTexture
    and it ends up re-creating the surface/a texture, while being in background

If I comment the line 683, hard-coding some size, black-scree disappears.

Not sure how to fix that ...

On 2019-06-17 19:07:31 +0000, Sylvain wrote:

Maybe ...

--- a/src/render/SDL_render.c Mon Jun 17 08:38:33 2019 -0700
+++ b/src/render/SDL_render.c Mon Jun 17 21:06:58 2019 +0200
@@ -680,11 +680,7 @@
/* Window was resized, reset viewport */
int w, h;

  •                if (renderer->GetOutputSize) {
    
  •                    renderer->GetOutputSize(renderer, &w, &h);
    
  •                } else {
                       SDL_GetWindowSize(renderer->window, &w, &h);
    
  •                }
    

On 2019-06-17 20:33:31 +0000, Sylvain wrote:

I think this fix the issue Jonas, can you also try ?

I move the sent of the resize event when the context get restored:
https://hg.libsdl.org/SDL/rev/ab4d52e38c42

On 2019-06-17 20:34:40 +0000, Sylvain wrote:

*** Bug 3628 has been marked as a duplicate of this bug. ***

On 2019-06-18 06:17:21 +0000, Ellie wrote:

I think this fix the issue Jonas, can you also try ?

With ab4d52e38c42 resizing is now broken for the OpenGL/accelerated SDL_Renderer which previously worked fine: no errors or blackscreen, but if I enter side by side or change orientation it will simply stoically stick to the old size no matter how far it's cut off

On 2019-06-18 08:52:00 +0000, Sylvain wrote:

Ok. I didn't like it very much neither because it changes the event sequence. So removed: https://hg.libsdl.org/SDL/rev/c4db6eade632
Though, I still saw things getting updated in opengles2 ...

Here's a new fix not to use the GetOutputSize() for the Android Software renderer

https://hg.libsdl.org/SDL/rev/160c6eede02c
It will use SDL_GetWindowSize() instead.
Please let me know.

Also, I thing there may some issue interfering:
in SDLActivity.java

Sometime we "skip" a false resume to avoid a glitch in the screen.

     if (skip) {
        Log.v("SDL", "Skip .. Surface is not ready.");
        mIsSurfaceReady = false;
        return;
     }

This is on purpose, and ok with full-screen, but not with resizing: it may fail to resume.
for instance if you want a Portrait App, but your resize to a Landscape size.

You may want to comment those 5 lines.
And I need to see if this java thing is still valid.

On 2019-06-18 09:42:44 +0000, Sylvain wrote:

the Java issue seems still need to prevent, I just unactivated in MultiWindow:

https://hg.libsdl.org/SDL/rev/8f76265cbd5b

On 2019-06-18 16:44:45 +0000, Sylvain wrote:

reverted SW_GetOutputSize https://hg.libsdl.org/SDL/rev/f92b7ee0dec3
and another attempt:
https://hg.libsdl.org/SDL/rev/e8a2d4743bc3

On 2019-06-18 16:54:45 +0000, Sylvain wrote:

reverted again: https://hg.libsdl.org/SDL/rev/e46fc7b6d880

On 2019-06-18 17:36:24 +0000, Sylvain wrote:

Sam's patch seems to be working for me: https://hg.libsdl.org/SDL/rev/1e71522317eb

On 2019-06-18 18:57:34 +0000, Sam Lantinga wrote:

Great! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant