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 2043

Summary: [Android] Calling SDL_VideoInit after SDL_Init with no parameters crashes the app
Product: SDL Reporter: Joe LeVeque <joeleveque>
Component: videoAssignee: Sylvain <sylvain.becker>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: gabomdq
Version: 2.0.0   
Hardware: ARM   
OS: Android (All)   

Description Joe LeVeque 2013-08-15 14:14:38 UTC
I'm trying to get my app to run in landscape mode only on Android. I tried setting the orientation in AndroidManifest.xml to no avail, so instead I added the following java code in onCreate(): 

// Force landscape orientation
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

This does force the orientation to rotate when the app starts, and appears to prevent the screen from rotating while the app is running - that's great. If my phone is already in landscape mode when I launch the app, the app runs fine. However, if the phone is in portrait mode when the app is launched, the app will start, but will be killed after a frame or two and I see the following in the logcat:

E/libEGL(3988): call to OpenGL ES API with no current context (logged once per thread)
D/dalvikvm(3988): threadid=15: thread exiting, not yet detached (count=0)
I/WindowState(699): WIN DEATH: Window{41ca3af8 u0 SurfaceView}
I/ActivityManager(699): Process <apk name> (pid 3988) has died.
W/ActivityManager(699): Force removing ActivityRecord{41e487b0 u0 <activity name>}: app died, no saved state
I/WindowState(699): WIN DEATH: Window{41c8b550 u0 <activity name>}

So, it appears as though the OpenGL context is somehow getting trashed even though the context isn't getting created until after the rotation has been done. This appears to be a bug in SDL2.

No evidence of a crash, and no stack trace is generated. It seems as though the app is somehow exiting normally. I'm willing to help find and fix this issue.
Comment 1 Joe LeVeque 2013-08-15 21:31:04 UTC
Update:

This seems to be related to calling SDL_Init() without SDL_INIT_VIDEO, and subsequently calling SDL_VideoInit(NULL) at a point later in code. I replaced the above with SDL_Init(SDL_INIT_EVERYTHING), and the problem disappears.
Comment 2 Gabriel Jacobo 2013-08-15 22:20:15 UTC
There's a few changes coming in the EGL management code on Android (see #2037) that will hopefully reduce the crazyness of SDL on Android. Let's revisit this after that patch lands.
Comment 3 Gabriel Jacobo 2013-11-06 14:25:38 UTC
Are you still seeing this issue?
Comment 4 Joe LeVeque 2013-11-06 19:11:46 UTC
Since I found that calling SDL_Init(SDL_INIT_EVERYTHING) works without issue, I had been using that in my code. However, I just switched my code back to call SDL_Init() without SDL_INIT_VIDEO, and then call SDL_VideoInit(NULL) later, and unfortunately, the problem reappeared with the exact same symptoms and logcat output.
Comment 5 Sylvain 2017-08-23 13:55:25 UTC
I tried and it seems to be working.

( setting landscape in onCreate(), starting in portrait, using SDL_VideoInit(NULL))
Comment 6 Sam Lantinga 2017-09-04 20:41:26 UTC
This seems to be fixed in the latest SDL snapshot:
http://www.libsdl.org/tmp/SDL-2.0.zip

Please reopen this bug if you can reproduce this with the same output.

Thanks!