emscripten-core / emscripten-core/emscripten

Destroying renderer and creating new one causes mouse events to stop firing

Aperta
#17,005 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C++
Stelle
27.6k
Fork
3.6k
Merge medio
1g 14h
PR unite (30g)
125

Descrizione

**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
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con il riproduttore in test.cpp e compilalo usando il comando em++ fornito. Traccia le chiamate a SDL_CreateRenderer e SDL_DestroyRenderer prima di emscripten_set_main_loop, confrontando il comportamento con quello ottenuto rimuovendo queste righe. Il lavoro è completato quando gli eventi di movimento del mouse e dei pulsanti vengono generati dopo la ricreazione del renderer.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp, wasm
Ambito
computer-graphics, web-dev
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.