为什么此代码使用SDL过滤事件无法正常工作?

根据SDL2 wiki,

SDL_SetEventFilter:使用此函数设置一个筛选器,以在所有事件更改内部状态并将其发布到内部事件队列之前处理所有事件。

void SDL_SetEventFilter(SDL_EventFilter filter,void * userdata)

filter的函数原型是:int YourEventFilter(void * userdata,SDL_Event * event)

所以,我的代码如下所示:

`

#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()); } else { //Create window window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if (window == NULL) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); } else { bool black = false; //Get window surface screenSurface = SDL_GetWindowSurface(window); SDL_SetEventFilter(isMouseEvent); bool isOn = true; while (isOn) { //Pump events SDL_PumpEvents(); SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF)); //Update the surface SDL_UpdateWindowSurface(window); } } } //Destroy window SDL_DestroyWindow(window); //Quit SDL subsystems SDL_Quit(); return 0; } int isMouseEvent(SDL_Event* ev) { if(ev!=NULL) { if (ev->type == SDL_MOUSEMOTION) return 0; } return 1; } 

但是,当代码运行时,没有事件被过滤,每个传递给isMouseEvent()的事件都是空的。 SDL2 Wiki非常简单,使用SDL_SetEventFilter的例子非常基本,不能正常工作。 任何想法,我应该从这里去看,因为从isMouseEvent()函数检查事件是不断null?

void指针不能简单的被省略。 尽管如此,请随意传递NULL。