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

SDL_GL_CreateContext crashes on android when SDL_GL_MULTISAMPLESAMPLES is used #3296

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.

These attachments are available in the static archive:

Reported in version: 2.0.10
Reported for operating system, platform: Android (All), ARM

Comments on the original bug report:

On 2019-06-21 12:58:21 +0000, wrote:

Sdl2 version: hg tip 89b3e1e9839c

I am testing kivy app built with python-for-android.

If multisamples is enabled, the app dies with an error:
SDL_GL_CreateContext(self.win): Unable to make EGL context current (call to eglMakeCurrent failed, reporting an error of EGL_BAD_SURFACE)

The relevant kivy sdl2 window init code does a lot of different things: https://github.com/kivy/kivy/blob/master/kivy/core/window/_window_sdl2.pyx#L76

But i believe that minimal code to reproduce is this:
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1)
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2)
self.win = SDL_CreateWindow(NULL, x, y, width, height, self.win_flags)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0)
self.ctx = SDL_GL_CreateContext(self.win)

The bug is gone when multisamples are disabled in kivy (the first two lines in the code above)

On 2019-06-21 16:58:25 +0000, wrote:

Ah, issue with EGL_BAD_SURFACE is more complicated. For more complex app, even without multisampling the chance of successful start is about 30%

On 2019-06-21 18:25:44 +0000, wrote:

this is the adb log of when the app crashes: https://gist.github.com/Fak3/429328b50c9eb11b8c896ad73e236a1a

On 2019-06-21 20:58:49 +0000, Sam Lantinga wrote:

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

Thanks!

On 2019-06-21 20:59:19 +0000, Sam Lantinga wrote:

Whoops, didn't mean to mark this fixed.

On 2019-06-22 06:29:43 +0000, Sylvain wrote:

I tried those flags, and I could always start my app and/or create a GL context.
I tried several times to makes sure about the 30% ratio.

This is not clear, if the issue is with the attributes MULTISAMPLE, it should always happen, right?

But if the issue is with the MakeCurrent failing, so it shouldn't be related to your attributes, and fail with any context ?! And you should check when current is made.

Maybe, you should try with simple C app to reduce the scope of the issue.

On 2019-06-22 12:17:17 +0000, wrote:

Maybe Multisample just makes the bug to appear a bit more reliably, but it is not crucial for the app to crash.

Is there any tutorial of how to build an app for android?

I bisected and tested my app against repo history.

The last known changeset that works fine is this:

Android: make sure surfaceChanged try to enter into 'resumed' state.
Wed, 02 Jan 2019 17:41:33 +0100 (5 months ago)
changeset 12492 fe136f38ab71

Then changesets 12493-12511 crash app because of a different issue, related to concurrency (i think), and throw segfaults.

And then the first changeset that fixes concurrency but experince this topic issue with EGL_BAD_SURFACE is this:

Android: concurrency issue for Android_SetWindowFullscreen()
Wed, 09 Jan 2019 15:18:41 +0100 (5 months ago)
changeset 12512 afc8e5d1d992

So the bug was introduced between 02 Jan and 09 Jan, somewhere in changesets 12493-12512

On 2019-06-22 12:28:50 +0000, Sylvain wrote:

So this commit introduce the issue ?
https://hg.libsdl.org/SDL/rev/afc8e5d1d992
It only adds some synchronization to make the function call be atomic.
So this is strange :/

Can you try to use RGB 565 instead of 888 in you KIVY code ?!

At the same time, here's some docs for android:
https://hg.libsdl.org/SDL/file/afc8e5d1d992/docs/README-android.md
there is also a script:
https://hg.libsdl.org/SDL/file/afc8e5d1d992/build-scripts/androidbuild.sh
not sure how much it can help

but in short ...
You need to have android ndk, you can build with ndk-build
you need also to setup some gradle build file also.

On 2019-06-22 12:41:59 +0000, wrote:

So this commit introduce the issue ?
https://hg.libsdl.org/SDL/rev/afc8e5d1d992

I don't know if it was this commit, because ~20 commits before this one, from 12493 to 12511 mask the EGL_BAD_SURFACE error with another error.

Can you try to use RGB 565 instead of 888 in you KIVY code ?!

Kivy does this right now:
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16)
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8)
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8)
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8)
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8)
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8)
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0)
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1)

How should i make it use RGB 565 properly? Just change three lines?

On 2019-06-22 12:47:15 +0000, Sylvain wrote:

remove
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8)
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8)
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8)
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8)

add

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5)
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 6)
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5)

On 2019-06-22 12:51:35 +0000, Sylvain wrote:

Also if you could bisect a little bit more to find the commit with issue

On 2019-06-22 12:54:52 +0000, Sylvain wrote:

also, there is a mistake:
not

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5)
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 6)
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5)

but

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5)
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5)
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 6)

(RGB == 565)

On 2019-06-22 12:55:17 +0000, Sylvain wrote:

sorry:
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5)
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6)
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5)

On 2019-06-22 13:46:45 +0000, wrote:

Ok, rgb 565 works fine and doesn't crash.

On 2019-06-22 15:07:36 +0000, Sylvain wrote:

Ok, another try:

Can you set-back ARGB8888
And comment out this line in the java file:

https://hg.libsdl.org/SDL/file/5cbf6472a916/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java#l1138

On 2019-06-22 15:55:16 +0000, wrote:

commented this line, and app works fine. But SDL reports that format is 565:

V/SDL (26215): pixel format RGB_565

should it be like that?

btw, i am testing commit afc8e5d1d992 (first known failing one), not the tip

On 2019-06-22 19:35:08 +0000, Sylvain wrote:

You can also try with latest, but I believe it would be the same.

Can you provide me an APK which fails so that I can try ?

Can you tell which phone you use ? which android version also ?

On 2019-06-22 20:10:24 +0000, wrote:

failing apk: https://drive.google.com/file/d/1G7qIJfRdAy87d2Qe_XX3oBA4HX__c6dk/view?usp=sharing

the device is zte nubia z11 mini
Amdroid 5.1.1

V/SDL (25270): Device: NX529J
V/SDL (25270): Model: NX529J
V/SDL (25270): Window size: 1080x1920
V/SDL (25270): Device size: 1080x1920
I/python (25270): [INFO ] [GL ] Using the "OpenGL ES 2" graphics system
I/python (25270): [INFO ] [GL ] Backend used
I/python (25270): [INFO ] [GL ] OpenGL version <b'OpenGL ES 3.1 V@124.0 (GIT@I041b18199e)'>
I/python (25270): [INFO ] [GL ] OpenGL vendor <b'Qualcomm'>
I/python (25270): [INFO ] [GL ] OpenGL renderer <b'Adreno (TM) 405'>
I/python (25270): [INFO ] [GL ] OpenGL parsed version: 3, 1
I/python (25270): [INFO ] [GL ] Texture max size <16384>
I/python (25270): [INFO ] [GL ] Texture max units <16>

On 2019-06-23 06:58:42 +0000, Sylvain wrote:

I tried but this is not clear to me to see any issue. It doesn't crash.
I dont get the same log you published with "Unable to get a Window, abort."

(I may need to test on an older device)

I notice it gets stuck in "Loading" and I have to go to background/foreground so that it continues. Then it display "L hi 1 "

Did you try to run a sample SDL2 C app ?

On 2019-06-23 07:09:52 +0000, wrote:

Where can I get the sample c app?

On 2019-06-23 13:23:56 +0000, Sylvain wrote:

Created attachment 3842
test.c

Here's a minimal in order to create a test-case.

Modify it and try to get it crashing with the multisample enable.

On 2019-06-23 14:15:11 +0000, Sylvain wrote:

I have a device where your .apk fails with:
[CRITICAL] [App ] Unable to get a Window, abort.
(Samsung S5 Android 6.0.1)

but, on this same device, If run another app, armeabi-v7a, modified with:

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16)
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8)
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8)
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8)
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8)
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8)
    SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0)
    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1)
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1)
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2)
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2)
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0)

this is working.

On 2019-06-23 15:09:26 +0000, wrote:

I have a device where your .apk fails with: [CRITICAL] [App ] Unable to get a Window, abort. (Samsung S5 Android 6.0.1)

Look about 20 lines above the error - does it say this:

I/python ( 9712): [CRITICAL] [Window ] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
I/python ( 9712): sdl2 - RuntimeError: b'Unable to make EGL context current (call to eglMakeCurrent failed, reporting an error of EGL_BAD_SURFACE)'
I/python ( 9712): File "/home/u1/.local/share/python-for-android/build/python-installs/paradox/kivy/core/init.py", line 70, in core_select_lib
I/python ( 9712): File "/home/u1/.local/share/python-for-android/build/python-installs/paradox/kivy/core/window/window_sdl2.py", line 152, in init
I/python ( 9712): File "/home/u1/.local/share/python-for-android/build/python-installs/paradox/kivy/core/window/init.py", line 969, in init
I/python ( 9712): File "/home/u1/.local/share/python-for-android/build/python-installs/paradox/kivy/core/window/window_sdl2.py", line 289, in create_window
I/python ( 9712): File "kivy/core/window/_window_sdl2.pyx", line 233, in kivy.core.window._window_sdl2._WindowSDL2Storage.setup_window
I/python ( 9712): File "kivy/core/window/_window_sdl2.pyx", line 75, in kivy.core.window._window_sdl2._WindowSDL2Storage.die

?

On 2019-06-23 20:18:52 +0000, Sylvain wrote:

Yes, same log

On 2019-06-26 04:42:40 +0000, wrote:

Putting Android activity lock around all the sdl calls makes this bug go away

On 2019-06-28 14:42:36 +0000, Sylvain wrote:

commit https://hg.libsdl.org/SDL/rev/dd9169424181
details in bug # 4681

On 2019-07-01 05:02:35 +0000, wrote:

This bug is resolved with https://hg.libsdl.org/SDL/rev/dd9169424181
Closing.

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