-
Notifications
You must be signed in to change notification settings - Fork 64
Creating, Deleting and Recreating a SDL GL Context stops Mouse events #92
Comments
Hmm, I couldn't reproduce with this: // emcc -s USE_SDL=2
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include "SDL.h"
#include <stdio.h>
static int run = 1;
SDL_Window *window;
void loop() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_MOUSEMOTION:
printf("motion %i %i\n", event.motion.x, event.motion.y);
break;
case SDL_QUIT:
run = 0;
break;
}
}
}
int main(int argc, char *argv[]) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
return (1);
}
window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
SDL_GLContext ctx = SDL_GL_CreateContext(window);
SDL_GL_DeleteContext(ctx);
ctx = SDL_GL_CreateContext(window);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (run) loop();
#endif
return (0);
} Also, if it helps narrow this down, these are the non-upstream changes between 17 and 18: version_17...3a222fc (the rest is 2.0.7 -> 2.0.9) |
I'll try to test with only theese changes later. My app is a lot bigger and is kinda legacy stuff, hard to pinpoint the exact cause, but removing the SDL_GLContext recreation fixed it. So I guess this is somewhere around there. Also, the actual delete and recreate happens in the main loop. And also, the mouse is set as relative. |
I'm also having this problem, though I don't set up contexts directly, I use renderers. If you destroy one and recreate another one for the same window, mouse events vanish. Modifying your example:
|
Hmm, just destroying the renderer is enough... Digging down a bit, it looks like Emscripten removes ALL event handlers from a canvas when you destroy a GL context: https://github.com/emscripten-core/emscripten/blob/master/src/library_webgl.js#L999. |
Ah, I guess that's this, then: emscripten-core/emscripten#9803 Seems I can work around it myself by just not recreating the renderer. I thought I was doing that because I had to on window resize, but it seems to work fine in Linux, emscripten, Windows (well, Wine). Not tested macosx yet. Edit: I was wrong. It is needed when resizing, or you get some strange scaling effects. |
This seems to be a regression since v17, as the bug didn't existed in v17.
In v18, when doing
this stops mouse events from being dispatched via SDL_PollEvent. They just doesn't appear no matter what do I do.
The bug is nonexistant in non-EMSCRIPTEN environment (i.e. when built with SDL on Windows)
The text was updated successfully, but these errors were encountered: