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 5527

Summary: Crash at the SDL_EGL_MakeCurrent() call on Android 5.1
Product: SDL Reporter: Vitaly Novichkov <admin>
Component: videoAssignee: Sam Lantinga <slouken>
Status: NEW --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sylvain.becker
Version: 2.0.14   
Hardware: ARM   
OS: Android (All)   
Attachments: Screenshot of the crash moment
Detailed variables 1 and stack trace for the crash moment
Detailed variables 2

Description Vitaly Novichkov 2021-02-02 21:06:54 UTC
Created attachment 4749 [details]
Screenshot of the crash moment

On Android 5 I found the next case:
- Having a separated "launcher" activity
- Starting the SDL-based activity by button press and then `.finish()` the "launcher" activity
- It starts normally and works normally
- Using SDL Renderer API with the accelerated context
- Inside of onDestroy() at my class, call the `System.exit(0);`
- Starting the app again
- Pressing the start button at the "launcher" activity
- Attempt to initialize the context causes the SIGSEGV crash at the SDL_EGL_MakeCurrent()
- All the test was done on the Archos c70 Xenon tablet with Android 5.1.

I had attached the screenshot of the problem. I do use the SDL 2.0.14 release. I had to check HG for any OpenGL ES related commits and seems nothing was found interesting.

Gonna try to run this at the emulator, will it be reproduced the same or not?
Comment 1 Vitaly Novichkov 2021-02-02 21:14:26 UTC
Created attachment 4750 [details]
Detailed variables 1 and stack trace for the crash moment
Comment 2 Vitaly Novichkov 2021-02-02 21:14:52 UTC
Created attachment 4751 [details]
Detailed variables 2
Comment 3 Sylvain 2021-02-03 07:19:46 UTC
Do you have

android:launchMode="singleInstance"

in you AndroidManifest.xml for your activities ?
Comment 4 Vitaly Novichkov 2021-02-03 07:55:56 UTC
(In reply to Sylvain from comment #3)
> Do you have
> 
> android:launchMode="singleInstance"
> 
> in you AndroidManifest.xml for your activities ?

It's done for only one activity - the SDL-based one, do you suggest me to make it on both launcher and SDL-based? Gonna try...
Comment 5 Vitaly Novichkov 2021-02-03 08:54:55 UTC
> android:launchMode="singleInstance"

Didn't helped

----

Okay, I may guess that the reason for this because when I close the application and doing clean-up, I do:
- SDL_HideWindow(window) // 
- SDL_SetWindowFullscreen(window, SDL_FALSE) // on Android game is always full-screen
- SDL_SetWindowSize() // restoring original size of the window

And during the startup:
- SDL_CreateWindow
- SDL_SetWindowMinimumSize
- SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP)
- SDL_PollEvents while window is still hidden
- Attempt to load any graphics causes the crash:
-- SDL_CreateRGBSurfaceFrom
-- SDL_CreateTextureFromSurface
-- SDL_FreeSurface
or at an attempt to poll events at some moment, etc.
Comment 6 Vitaly Novichkov 2021-02-03 09:17:03 UTC
Okay, seems the issue has gone when I do a show of the window after I created it. If I do textures loading while the window is hidden, it will crash on startup.
Comment 7 Vitaly Novichkov 2021-02-03 09:17:59 UTC
Also, when closing the application, don't hide the window until destroy all textures.
Comment 8 Vitaly Novichkov 2021-02-03 09:27:27 UTC
Oh! One thing I just now reminded! Before I made the launcher activity, the game worked perfectly and started with no crashes. The crash got introduced once I started to use the launcher activity. I do call next:

        Intent myIntent = new Intent(Launcher.this, thextechActivity.class);
        Launcher.this.startActivity(myIntent);
        Launcher.this.finish();

to start it. Should I also specify some to make sure the "single instance" works?
Comment 9 Sylvain 2021-02-03 12:46:34 UTC
you may also use android:alwaysRetainTaskState="true"


to make sure single instance works,
maybe add static int variable in you activity class,
log it and increment it in onCreate()
it should remains at 0 each time.

(don't do anything, in one destroy because it may be never called)

check maybe if the C code is also not loaded more than once ?
Comment 10 Vitaly Novichkov 2021-02-03 22:12:43 UTC
> you may also use android:alwaysRetainTaskState="true"

That's already at my SDL-based activity

> to make sure single instance works,
> maybe add static int variable in you activity class,
> log it and increment it in onCreate()
> it should remains at 0 each time.

I'll try this to check...

> check maybe if the C code is also not loaded more than once?

That right, because the crash happens at C code side