emscripten-core / emscripten-core/emscripten
Destroying renderer and creating new one causes mouse events to stop firing
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.11-git (864a2347a28f3252bff584f9fda966f94b135c77)
clang version 15.0.0 (https://github.com/llvm/llvm-project d14f2a6359483730657b275d40822d1098e3ff51)
Target: wasm32-unknown-emscripten
Thread model: posix
```
If calling `SDL_CreateRenderer` then `SDL_DestroyRenderer` and then creating a new renderer, the mouse input events fail to fire. In my case, this can easily be designed around and probably wasn't a good idea in the first place, but I figured I would post it since it was the reason mouse input wasn't working on web but working on desktop. The following program doesn't capture mouse input, but the same program with the create and destroy lines commented out is working.
```c++
#include
#include
void loop()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch(event.type){
case SDL_MOUSEMOTION: {
SDL_MouseMotionEvent *m = (SDL_MouseMotionEvent*)&event;
printf("motion : %d,%d %d,%d\n", m->x, m->y, m->xrel, m->yrel);
break;
}
case SDL_MOUSEBUTTONDOWN: {
SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event;
printf("button down : %d,%d %d,%d\n", m->button, m->state, m->x, m->y);
break;
}
case SDL_MOUSEBUTTONUP: {
SDL_MouseButtonEvent *m = (SDL_MouseButtonEvent*)&event;
printf("button up : %d,%d %d,%d\n", m->button, m->state, m->x, m->y);
break;
}
}
}
}
int main(int, char**)
{
SDL_Window* window = SDL_CreateWindow("Test", 0, 0, 640, 480, 0);
SDL_Renderer* renderer;
/* Comment out the following two lines to get mouse events working */
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_DestroyRenderer(renderer);
renderer = SDL_CreateRenderer(window, -1, 0);
emscripten_set_main_loop(loop, 0, 1);
return 0;
}
```
To compile, I'm using
```
em++ -s USE_SDL=2 test.cpp -o test.html
```
Contributor guide
Assessment
This issue has not been assessed yet.