Don`t work SDL_PollEvents


#1

Hello all, im try porting windows-only game and try replace dinput on SDL. Code look like:

SDL_Init(SDL_INIT_EVENTS);
...
while(true)
{
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
        printf("some event\n");
    }
}
...
SDLQuit();

Problem: SDL_PollEvent always return 0.
What Im do wrong? Need mandatory create context and window? Or something else?


#2

I do believe you need a window before you can get events,


#3

This not work:( Im created Window and Renderer, but still cannot get any event. And so strange - if I do SDL_Init(SDL_INIT_VIDEO), at call SDL_PollEvent just crash, if replace SDL_INIT_VIDEO on SDL_INIT_EVERYTHING - working…


#4

You should be able to use SDL_INIT_VIDEO as this initialises the event system for you. Can you send me a sample of your code so I can see whats happening please.


#5

Problem solved, before main loop need call SDL_PumpEvents().
Code sample can see there: https://github.com/q4a/xray-16/tree/sdl2

src/xrEngine/xr_input.cpp - Loop with SDL_PollEvents()
src/xrEngine/device.cpp - init loop with SDL_PumpEvents()
src/xrEngine/Device_Initialize.cpp - SDL_Init()


#6

Strange you need to call pumpevents as SDL poll event implicitly calls this for you.

Is the event handling done in the same thread where the window lives ?


#7

Yes, in same thread.