Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allowed one SDL_SetEventFilter #28

Closed
jeffphilp opened this issue May 17, 2016 · 3 comments
Closed

Only allowed one SDL_SetEventFilter #28

jeffphilp opened this issue May 17, 2016 · 3 comments

Comments

@jeffphilp
Copy link

Hi,

Code was added recently due to poor Windows event pumping at https://github.com/FNA-XNA/FNA/blob/master/src/SDL2/SDL2_FNAPlatform.cs#L160 which makes use of an SDL_SetEventFilter. However it looks like after googling it, that SDL only supports a single EventFilter (and multiple event watchers) which means its now not possible to intercept the events being polled by the main FNA loop.

I was trying to make use of the EventFilter to catch SDL_EventType.SDL_QUIT and use that to delay the closing so I can put up a prompt for the user to Save before quitting or just to cancel the close. However it clashes with FNAs usage because I am in the unfortunate position of being on Windows and allowing user resizing.

I was wondering if you have any ideas for how this can be handled without changing the FNA code?

Thanks in advance.

@flibitijibibo
Copy link
Member

You can set your own filter that overrides ours, as SDL will throw out the previous filter when setting:

https://hg.libsdl.org/SDL/file/5b61e12c0a30/src/events/SDL_events.c#l480

You can pull in what FNA's doing and get the same thing, you'd just have to inline this redraw func:

https://github.com/FNA-XNA/FNA/blob/master/src/Game.cs#L591

As long as you add the filter after we've added ours you'll be fine, and because of that you can probably skip that TimeSpan.Zero check too, so it should be 100% compatible with the public API for Game.

@jeffphilp
Copy link
Author

Yeah that seems to be the best, thanks for your help.
This project really is awesome.

Is that windows pumping issue just a problem in the current SDL library? or is there something fundamentally which prevents windows providing the required events?

@flibitijibibo
Copy link
Member

It appears to be a fundamental problem with Windows. I have a patch submitted to do the InvalidateRect call:

https://bugzilla.libsdl.org/show_bug.cgi?id=3307

The problem is that Windows stalls everything (but it does still send events to the WndProc) when resizing, so we'd only redraw after the user has finished resizing. I'm hoping to get the InvalidateRect part in at least, but the event timings are something that may be unfixable.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants