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 1819

Summary: crash during SDL_GL_CreateContext on iOS
Product: SDL Reporter: Wouter van Oortmerssen <aardappel>
Component: *don't know*Assignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq
Version: HG 2.0   
Hardware: iPhone/iPod touch   
OS: Other   

Description Wouter van Oortmerssen 2013-04-23 20:12:07 UTC
#0	0x01d1e881 in __HALT ()
#1	0x01c58971 in _CFRuntimeCreateInstance ()
#2	0x02e4acc1 in GSFontCreateWithName ()
#3	0x00adc0e1 in UINewFont ()
#4	0x00adc24c in +[UIFont systemFontOfSize:traits:] ()
#5	0x00adc298 in +[UIFont systemFontOfSize:] ()
#6	0x009fb5d9 in +[UITextFieldLabel defaultFont] ()
#7	0x00a8ccd5 in -[UILabel _commonInit] ()
#8	0x00a8ce14 in -[UILabel initWithFrame:] ()
#9	0x00a052eb in -[UITextField createTextLabelWithTextColor:] ()
#10	0x009fbede in -[UITextField initWithFrame:] ()
#11	0x00152ead in -[SDL_uikitview initializeKeyboard] at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/uikit/SDL_uikitview.m:208
#12	0x0015290c in -[SDL_uikitview initWithFrame:] at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/uikit/SDL_uikitview.m:50
#13	0x00153b5b in -[SDL_uikitopenglview initWithFrame:scale:retainBacking:rBits:gBits:bBits:aBits:depthBits:stencilBits:majorVersion:] at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/uikit/SDL_uikitopenglview.m:53
#14	0x001524ff in UIKit_GL_CreateContext at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/uikit/SDL_uikitopengles.m:114
#15	0x0015078f in SDL_GL_CreateContext at /Users/aardappel/lobster/external/SDL-2.0.0-7046/Xcode-iOS/SDL/../../src/video/SDL_video.c:2666
#16	0x000d8c5c in SDLInit(char const*, vec<int, 2>&) at /Users/aardappel/lobster/dev/xcode/lobster/../../src/sdlsystem.cpp:193

called by my code:

    _sdl_window = SDL_CreateWindow(title,
                                    SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                    1024, 768,
                                    SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

    assert(_sdl_window);

    _sdl_context = SDL_GL_CreateContext(_sdl_window);

using the iPad simulator.

SDL-2.0.0-7046
Comment 1 Wouter van Oortmerssen 2013-04-23 20:14:55 UTC
oops, copy pasted the wrong CreateWindow call, it is actually:

    _sdl_window = SDL_CreateWindow(title,
                                    0, 0,
                                    1024, 768,
                                    SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS);
Comment 2 Wouter van Oortmerssen 2013-06-02 16:07:21 UTC
this seems to have a similar stack trace (see first comment) but I have no idea how their problem relates to the SDL code: http://stackoverflow.com/questions/1976539/iphone-unittesting-uitextfield-value-and-otest-error-133
Comment 3 Wouter van Oortmerssen 2013-06-02 16:33:17 UTC
Got around it for now by commenting out [self initializeKeyboard].
Setting SDL_IPHONE_KEYBOARD to 0 produced other compile errors.
Comment 4 Wouter van Oortmerssen 2013-06-02 17:21:04 UTC
I'm guessing something bigger is wrong with the IOS port, since it's not rendering anything, not even glClear does anything, for code which used to work with older versions of SDL (1.3)
Comment 5 Sam Lantinga 2013-06-02 23:08:31 UTC
I'm not having any troubles here.  Do the test programs work for you?
Are you pumping the event loop?
Comment 6 Wouter van Oortmerssen 2013-06-03 12:33:18 UTC
Not sure why you ask about pumping the event loop.. the crash (see callstack above) is inside SDL_GL_CreateContext which I call way before I start my event loop (first call to SDL_PollEvent).

Just ran testsdl on the iPad hardware, and this is the output:

--

Platform : All tests successful (2)
SDL_RWops : All tests successful (5)
Rect : All tests successful (1)
Assert Failed!
   Primitives output not the same.
   Test Case 'Load Test'
   Test Suite 'SDL_Surface'
   Last SDL error 'Couldn't open good.bmp'
Assert Failed!
   Blitting blending output not the same (using SDL_BLEND_*).
   Test Case 'Blit Blending Tests'
   Test Suite 'SDL_Surface'
   Last SDL error 'Couldn't open good.bmp'
SDL_Surface : Failed 2 out of 4 testcases!
Assert Failed!
   Primitives output not the same.
   Test Case 'Renderer opengles2'
   Test Suite 'Rendering with uikit driver'
   Last SDL error 'Couldn't open good.bmp'
Assert Failed!
   Primitives output not the same.
   Test Case 'Renderer opengles'
   Test Suite 'Rendering with uikit driver'
   Last SDL error 'Couldn't open good.bmp'
Assert Failed!
   Blended primitives output not the same.
   Test Case 'Renderer software'
   Test Suite 'Rendering with uikit driver'
   Last SDL error 'Couldn't open good.bmp'
Rendering with uikit driver : Failed 3 out of 4 testcases!
Assert Failed!
   SDL_CreateWindow
   Test Case 'Initializing video mode'
   Test Suite 'Rendering with dummy driver'
   Last SDL error 'No OpenGL support in video driver'
Rendering with dummy driver : Failed 1 out of 1 testcases!
SDL_Audio : All tests successful (1)
Tests run with SDL 2.0.0 revision 502270
System is running iPhone OS and is little endian

--

Does that even test OpenGL ES 2? There certainly is no graphical output while this test runs.
Comment 7 Sam Lantinga 2013-06-03 22:51:55 UTC
Can you upload a sample project that I can use to reproduce the problem?

Thanks!
Comment 8 Wouter van Oortmerssen 2013-06-04 19:16:36 UTC
Sigh. The issue was a missing SDLMain.

I have all my SDL functionality in one .cpp file, and my main sits in another. The latter does not include SDL.h, because, well, it doesn't (appear to) use SDL. This caused the replacement main() to be excluded, which apparently is not a problem on the desktop platforms, but on IOS this particular crash is the result.

Entirely my fault, of course, but hard to track down, especially since there's no complaint on the other platforms, and SDL_Init and SDL_CreateWindow succeed just before this crash happens, giving the impression that there's nothing wrong with SDL's setup.

I would recommend SDL_init to fail with a specific error when the wrapper main() has never been called, at least on platforms that need the wrapper main to function.

Then again, it may be time to re-evaluate SDL's insistence on being main(), given that this model doesn't fit that well with IOS and Android anyway. A more modular approach would rock.
Comment 9 Sam Lantinga 2013-06-05 02:55:52 UTC
I'm going to reopen this, because you're right, SDL should warn you that you haven't used SDL's main()

If you have suggestions on how to change SDL on iOS so we don't need to do this, I'm all for it! :)
Comment 10 Wouter van Oortmerssen 2013-06-05 14:03:35 UTC
no, letting SDL_Init give an error is the easiest and least intrusive way to fix this.

What I am saying is that on platforms like iOS and Android, the ideal interface for SDL to have would not be this SDLMain macro thing, but instead ask the user to create a regular main(), that calls SDL_Run() or whatever which never returns (since these OSes want to own the main loop), and you set up some callbacks for init & frame rendering before you call it. That would be a major API change though assuming you'd want to do it on desktop also.
Comment 11 Sam Lantinga 2013-06-06 00:27:04 UTC
Okay, SDL_Init() will now fail if the application isn't initialized properly.
http://hg.libsdl.org/SDL/rev/cd5516b9263d

Thanks!