Some events issued on startup, such as SDL_DROPFILE deleted when event filter set

A fairly obscure one, but a bug nonetheless:

In my tvOS application I use a TopShelf extension to launch the application with a URL. The URL is passed into the openURL UIApplication delegate function and then ends up as an SDL_DROPFILE event.

However, it is added to the event queue before my main function has been called, and my main function needs to specify an event filter callback.

Unfortunately SDL_SetEventFilter flushes all events:

void
SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
{
    if (!SDL_event_watchers_lock || SDL_LockMutex(SDL_event_watchers_lock) == 0) {
        /* Set filter and discard pending events */
        SDL_EventOK.callback = filter;
        SDL_EventOK.userdata = userdata;
        SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);

        if (SDL_event_watchers_lock) {
            SDL_UnlockMutex(SDL_event_watchers_lock);
        }
    }
}

I believe the SDL_FlushEvents() call should be replaced with SDL_FilterEvents(filter, userdata) so that events the user/application wants to receive are not indiscriminately discarded.

With this change, my URL event arrives as expected and I can dequeue it and process it once my application has started up.

1 Like