| Summary: | SDL_RendererEventWatch doesn't always scale mouse events when SetLogicalSize is used | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Michał Zieliński <michal> |
| Component: | render | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | sezeroz, sylvain.becker |
| Version: | HG 2.1 | ||
| Hardware: | All | ||
| OS: | Android (All) | ||
| Attachments: |
check if logical_w_backup is set and if so, use *_backup members.
test case |
||
I just realized that this doesn't solve race condition, just makes it much harder to occur. The proper solution would need a mutex or some restructuring eliminating the need for *_backup variables. Out of curiosity, when are mouse events sent from non-main thread? On Android. I haven't tested to see the issue. But, if I understand it correctly, this happens because: 1/ android is sending Mouse event, so calling SDL_SendMouseButton(), SDL_PushEvent(), and SDL_RendererEventWatch() with logical_w/h and, at the same time, in a different thread: 2/ SDL_SetRenderTarget() is reconfiguring internal renderer data with different logical_w/h. If so, then this would also affect also touch events (now there handled by the EventWatch routine). And, if I read the SDL_RendererEventWatch() code, I see that a similar issue is fixed: https://hg.libsdl.org/SDL/rev/a8cbb653aea4 Created attachment 3013 [details]
test case
Here's a test-case !
It's not the usual way to do, but it shows clearly the issue without the need of threads.
Window as a size of 800x800
The renderer a logical size of 80x80
so I expect the mouse to be within [0; 80]x[0; 80]
But I use a target texture, and I poll events in the middle of using it.
I got event without the scale, e.g with [0; 800]x[0; 800].
Fixed the race condition for touch event: https://hg.libsdl.org/SDL/rev/27a1bea6bdff For Mouse events, this was fixed there: https://hg.libsdl.org/SDL/rev/3239c8ad2986 So I marked this as resolved |
Created attachment 1334 [details] check if logical_w_backup is set and if so, use *_backup members. There is a race condition when mouse events are sent from non-main thread. SDL_RendererEventWatch may end up being invoked when renderer is drawing on texture - logical_w is set to 0. Attached patch checks if logical_w_backup is set and if so, uses *_backup members.