We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4669 - Using the software SDL_Renderer on Android leads to GL errors & black screen when window resizes
Summary: Using the software SDL_Renderer on Android leads to GL errors & black screen ...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: HG 2.0
Hardware: x86_64 Linux
: P2 blocker
Assignee: Sylvain
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.10
: 3628 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-06-17 03:05 UTC by Ellie
Modified: 2019-06-22 18:32 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ellie 2019-06-17 03:05:38 UTC
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
1. Create a window and an SDL_Renderer with SDL_RENDERER_SOFTWARE
2. 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](this:0x7a1635a800,id:1068,api:1,p:2568,c:412) 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](this:0x7a1635c000,id:1098,api:1,p:-1,c:-1) disconnect(C)
06-13 02:09:46.510   412   412 I BufferQueue: [com.example.myapp/org.kivy.android.PythonActivity#0](this:0x7a1635c000,id:1098,api:1,p:-1,c:-1) ~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](this:0x7a16216800,id:1100,api:0,p:-1,c:412) setDefaultBufferSize: width=1006 height=1019
06-13 02:09:46.654   412   412 I BufferQueueConsumer: [SurfaceView - com.example.myapp/org.kivy.android.PythonActivity#0](this:0x7a16215000,id:1099,api:1,p:15784,c:412) 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](this:0x7a1addd000,id:1107,api:1,p:1931,c:412) 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)
Comment 1 Sam Lantinga 2019-06-17 15:41:07 UTC
Sylvain, can you look at this for SDL 2.0.10 release?

Thanks!
Comment 2 Sylvain 2019-06-17 19:02:19 UTC
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 ...
Comment 3 Sylvain 2019-06-17 19:07:31 UTC
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);
-                    }
Comment 4 Sylvain 2019-06-17 20:33:31 UTC
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
Comment 5 Sylvain 2019-06-17 20:34:40 UTC
*** Bug 3628 has been marked as a duplicate of this bug. ***
Comment 6 Ellie 2019-06-18 06:17:21 UTC
> 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
Comment 7 Sylvain 2019-06-18 08:52:00 UTC
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.
Comment 8 Sylvain 2019-06-18 09:42:44 UTC
the Java issue seems still need to prevent, I just unactivated in MultiWindow:

https://hg.libsdl.org/SDL/rev/8f76265cbd5b
Comment 9 Sylvain 2019-06-18 16:44:45 UTC
reverted SW_GetOutputSize https://hg.libsdl.org/SDL/rev/f92b7ee0dec3
and another attempt:
https://hg.libsdl.org/SDL/rev/e8a2d4743bc3
Comment 10 Sylvain 2019-06-18 16:54:45 UTC
reverted again: https://hg.libsdl.org/SDL/rev/e46fc7b6d880
Comment 11 Sylvain 2019-06-18 17:36:24 UTC
Sam's patch seems to be working for me: https://hg.libsdl.org/SDL/rev/1e71522317eb
Comment 12 Sam Lantinga 2019-06-18 18:57:34 UTC
Great! :)