Seg fault when using SDL_StartTextInput() and polling textinput events


Hi guys, I’ve got a bit of a weird one I’m trying to wrap my head around. When using SDL_StartTextInput(), followed by a normal event loop, something a bit like this;

while (!done) {
    SDL_Event event;
    if (SDL_PollEvent(&event)) {
        switch (event.type) {
            case SDL_TEXTINPUT:
                 // handle the text input event here
                 // blah blah rest of code complete the loops etc

I am getting seg faults when “Shift-3” is pressed (which on my UK keyboard corresponds to £). Everything else works fine, and I can string input all the rest of the symbols (!, ", %, etc…), capital letters (A, B, C) etc. But for some reason with SDL_StartTextInput() turned on polling a Shift-3 event causes immediate seg fault and crash, even if I comment out all of the handling code below PollEvent()

If I turn off SDL_StartTextInput() and handle keys in the usual way (SDL_KEYDOWN, using keysym and mod etc) then I don’t have a problem - but for convenience I’d like to use the textinput feature of SDL2.

I’m guessing this is some weird localization option, and if my keyboard was US keyboard it wouldn’t fault? Any work around for this? I’m running linux btw.

I did try googling this fault before posting, couldn’t find anything. I’m guessing its a bug with the SDL version I’m using…

Appreciate any help on this one guys, I’m making huge progress with a major project and but need to get input events nicely resolved!


I haven’t tried reproducing on Linux, but a couple questions/ideas:

  • which version of SDL2 did this happen with? If it’s an old SDL version it would be good to try 2.0.5 or current HG.
  • Assuming it’s an OS packaged version, I’d install the SDL2 debug symbols, run your app in gdb and print out the backtrace when it crashes.
  • if you build SDL from source, try the checkkeys sample app included in the SDL source. It shows a blank window and prints text input events in the terminal so you can easily try to reproduce this.


Hi Eric, thanks for the reply. In the end I’ve given up trying to use the text input feature, and have coded up a method to handle key modifiers and special characters etc. I did try building from source, didn’t make any difference. I’m convinced its something to do with non-standard (US) keyboard layouts, as a UK keyboard is virtually identical to a US keyboard, except for the addition of the ‘£’ sign. Though having said that the ‘#’ key and ‘~’ worked fine, and I think they are in different places on UK vs US keyboards… I should have tried changing my keyboard layout in Linux but didn’t get round to it…

Its a mystery! But I have resorted to handling key events using SDL_KEYDOWN checks now, and its all fine using that approach.

Thanks again for the reply.