SDL
SDL copied to clipboard
[SDL2] crash on wayland with SDL_PushEvent and SDL_TEXTINPUT
I had some code that was working, and when I tested recently it segfaulted. I was able to reproduce the minimum case below:
#include <SDL2/SDL.h>
int main(int argc, char* args[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Event evt;
memset( &evt, 0, sizeof(SDL_Event) );
evt.type = SDL_TEXTINPUT;
evt.text.timestamp = SDL_GetTicks();
evt.text.windowID = 0;
snprintf( evt.text.text, SDL_TEXTINPUTEVENT_TEXT_SIZE, "test" );
SDL_PushEvent(&evt); // SEGFAULT
return 0;
}
It crashes on my system:
- Arch Linux
- Wayland
- Plasma6
- Using sdl2-compat
Note the SDL3 equivalent doesn't seem to crash:
#include <SDL3/SDL.h>
#include <string.h>
int main(int argc, char* args[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Event evt;
memset( &evt, 0, sizeof(SDL_Event) );
evt.type = SDL_EVENT_TEXT_INPUT;
evt.text.timestamp = SDL_GetTicks();
evt.text.windowID = 0;
evt.text.text = "test";
SDL_PushEvent(&evt); // No problemo
return 0;
}
Issue is likely related to using a fixed sized buffer for SDL2, and a pointer in SDL3, but I haven't looked into it.