We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2107 - SDL_RendererEventWatch doesn't always scale mouse events when SetLogicalSize is used
Summary: SDL_RendererEventWatch doesn't always scale mouse events when SetLogicalSize ...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: HG 2.1
Hardware: All Android (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-21 20:07 UTC by Michał Zieliński
Modified: 2019-10-14 14:44 UTC (History)
2 users (show)

See Also:


Attachments
check if logical_w_backup is set and if so, use *_backup members. (1.99 KB, patch)
2013-09-21 20:07 UTC, Michał Zieliński
Details | Diff
test case (2.83 KB, text/x-csrc)
2017-10-20 15:27 UTC, Sylvain
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Zieliński 2013-09-21 20:07:00 UTC
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.
Comment 1 Michał Zieliński 2013-09-21 20:13:15 UTC
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.
Comment 2 Sam Lantinga 2013-09-28 06:32:54 UTC
Out of curiosity, when are mouse events sent from non-main thread?
Comment 3 Michał Zieliński 2013-09-28 08:39:14 UTC
On Android.
Comment 4 Sylvain 2017-10-20 13:10:19 UTC
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
Comment 5 Sylvain 2017-10-20 15:27:20 UTC
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].
Comment 6 Sylvain 2017-10-24 19:53:42 UTC
similar issue with bug 2020
Comment 7 Sylvain 2019-10-14 14:42:52 UTC
Fixed the race condition for touch event: https://hg.libsdl.org/SDL/rev/27a1bea6bdff
Comment 8 Sylvain 2019-10-14 14:44:30 UTC
For Mouse events, this was fixed there: https://hg.libsdl.org/SDL/rev/3239c8ad2986
So I marked this as resolved