According to the SDL2 wiki,

SDL_SetEventFilter : Use this function to set up a filter to process all events before they change internal state and are posted to the internal event queue.

void SDL_SetEventFilter(SDL_EventFilter filter, void* userdata)

The function prototype for filter is: int YourEventFilter(void* userdata, SDL_Event* event)

And so, my code as follows is:


#include <SDL.h>
#include <stdio.h>
#include <memory>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int isMouseEvent(SDL_Event* ev);

int main(int argc, char* args[])

    SDL_Event ev;

    //The window we'll be rendering to
    SDL_Window* window = NULL;

    //The surface contained by the window
    SDL_Surface* screenSurface = NULL;

    //Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
        printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());

        //Create window
        if (window == NULL)
            printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());

            bool black = false;

            //Get window surface
            screenSurface = SDL_GetWindowSurface(window);
            bool isOn = true;
            while (isOn)
                //Pump events

                SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));

                //Update the surface
    //Destroy window

    //Quit SDL subsystems

    return 0;

int isMouseEvent(SDL_Event* ev)
    if(ev!=NULL) {
        if (ev->type == SDL_MOUSEMOTION)
            return 0;
    return 1;

However, when the code is ran no events are filtered, every event passed to isMouseEvent() is null. The SDL2 Wiki is very bare, and the examples on using SDL_SetEventFilter are very basic and do not work properly. Any ideas as to where I should go from here, seeing as the events are constantly null when checked from the isMouseEvent() function?

  • \$\begingroup\$ void pointer is a pointer that can point at any data type. You are mixing it with default arguments that's what can be omitted. \$\endgroup\$ – concept3d Feb 13 '14 at 2:14
  • \$\begingroup\$ Yep, that's where I was mistaken at. I'm going to edit my question, now that this is compiling, the events are not being filtered. \$\endgroup\$ – Daniel Martin Feb 13 '14 at 3:09
  • \$\begingroup\$ Nevermind, I'm an idiot. Got it fixed now! Reading is power. \$\endgroup\$ – Daniel Martin Feb 13 '14 at 3:23
  • \$\begingroup\$ How did you fixed ? \$\endgroup\$ – eri0o May 17 '18 at 2:21

void pointers cannot simply be omitted. Feel free to pass NULL, though.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.