-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
State of the Windows platform ? #1429
Comments
One concrete example:
Is the Mutex protecting WindowState still needed ? |
@Osspial, I believe this recent change has broken the Windows platform in a few ways : 6a330a2#diff-d4d8c8dcf07874a35d08c6a70e0a6daf It most probably introduced this regression: #1427 I am also pretty sure it introduced #1391. And I found a suspect code change:
Here the test on msg after the PeekMessageW() call is pointless as we are in the case where there is no message. I will try to revert the fix and reproduce the missing RedrawRequested issue. |
I reverted 6a330a2 and was able to reproduce an issue that looks similar to the one addressed by that fix. If the user calls window.request_redraw() while handling the MainEventsCleared event, then the RedrawRequested event is sent on the next loop iteration and not the current iteration. I am now trying to fix the issue in a different way... |
For reference:
My understanding is that calling |
|
What I am seeing after reverting the commit is confirmed by the associated PR description (which I overlooked) : #1366 Continuing my effort to understand and fix On Windows, the current approach is to post a Other platforms use a different approach: they raise a flag or buffer the redraw internally when X11:
Wayland:
These approaches seem much easier to handle. Problem is that on Windows, the window struct does not have access to the event_loop or runner. @Osspial any thoughts on that ? |
Hey, thanks for opening an issue to keep track of all this. I'll write up a more thorough response within the next couple days when I've got the time to look into this more. Sorry I didn't get back on this sooner - I was fairly stressed over the past month and wasn't keeping tabs on Winit to help manage that, but I'm feeling quite a bit better now and should be able to respond more promptly for the foreseeable future.
The rationale behind using |
Hi @Osspial, Thanks for getting back! I have looked at the I also looked at how other platforms handle it and came up with this approach: #1461. Please take a look. We can discuss it further here or in the PR. |
If redrawing must occur only when receiving a WM_PAINT message then my PR does not comply. I am now looking into another approach using UpdateWindow instead. It looks promising. Looks like RedrawWindow can work in that mode too if the |
These panics were introduced by rust-windowing@6a330a2 Fixes rust-windowing#1391 Fixes rust-windowing#1400 Fixes rust-windowing#1466 Probably fixes other related issues See rust-windowing#1429
The So I went full circle and simply fixed the various panics using the current approach of calling Use cases that have been tested:
A few corner cases have not been tested:
|
These panics were introduced by rust-windowing@6a330a2 Fixes rust-windowing#1391 Fixes rust-windowing#1400 Fixes rust-windowing#1466 Probably fixes other related issues See rust-windowing#1429
These panics were introduced by rust-windowing@6a330a2 Fixes rust-windowing#1391 Fixes rust-windowing#1400 Fixes rust-windowing#1466 Probably fixes other related issues See rust-windowing#1429
The fullscreen and window_debug examples still panic when entering borderless or exclusive full screen mode. See #1469. The min_max_size example also panics (but not in master). Looking into it now. |
These panics were introduced by rust-windowing@6a330a2 Fixes rust-windowing#1391 Fixes rust-windowing#1400 Fixes rust-windowing#1466 Probably fixes other related issues See rust-windowing#1429
The remaining panics are all caused by calls to For now, all calls to |
And back to square one :( : #1461 (comment) Seems like PeekMessage can, under some conditions, dispatch messages [1][2].
Trouble is that the loop to drain WM_PAINT messages can end up dispatching messages other than WM_PAINT. These are then sent to the runner but the runner is in MainEventsCleared state and cannot handler them. This is also interesting https://devblogs.microsoft.com/oldnewthing/?p=36493 [1] https://www.gamedev.net/forums/topic/685863-win32-message-handling-questions/ |
These panics were introduced by rust-windowing@6a330a2 Fixes rust-windowing#1391 Fixes rust-windowing#1400 Fixes rust-windowing#1466 Probably fixes other related issues See rust-windowing#1429
Here is a backtrace that shows that PeekMessage sends messages. This is mentioned in doc.
In this case it is a A fix that seems to work is to pass the Edited to add this link : Non-Queued messages Edited: it is |
These panics were introduced by rust-windowing@6a330a2 Fixes rust-windowing#1391 Fixes rust-windowing#1400 Fixes rust-windowing#1466 Probably fixes other related issues See rust-windowing#1429
* On Windows, fix request_redraw() related panics These panics were introduced by 6a330a2 Fixes #1391 Fixes #1400 Fixes #1466 Probably fixes other related issues See #1429 * On Windows, replace all calls to UpdateWindow by calls to InvalidateRgn This avoids directly sending a WM_PAINT message, which might cause buffering of RedrawRequested events. We don't want to buffer RedrawRequested events because: - we wan't to handle RedrawRequested during processing of WM_PAINT messages - state transitionning is broken when handling buffered RedrawRequested events Fixes #1469 * On Windows, panic if we are trying to buffer a RedrawRequested event * On Windows, move modal loop jumpstart to set_modal_loop() method This fixes a panic. Note that the WM_PAINT event is now sent to the modal_redraw_method which is more correct and avoids an unecessary redraw of the window. Relates to but does does not fix #1484 * On Window, filter by paint messages when draining paint messages This seems to prevent PeekMessage from dispatching unrelated sent messages * Change recently added panic/assert calls with warn calls This makes the code less panicky... And actually, winit's Windoww callbacks should not panic because the panic will unwind into Windows code. It is currently undefined behavior to unwind from Rust code into foreign code. See https://doc.rust-lang.org/std/panic/fn.catch_unwind.html * add comments to clarify WM_PAINT handling in non modal loop * made redraw_events_cleared more explicit and more comments
We can close this issue now. |
Hi,
As a foreword, I am new to Rust and winit. Also, English is not my native language, so please take what follows with a grain of salt.
My understanding about winit on Windows is that:
I've been looking at the code to address some issues [1][2][3] and it looks like the Windows code has inherited some complexity from the time it was multi threaded (?).
Thing's I have noticed:
I am open to be given directions or to discuss ways to improve the situation if it needs to.
[1] #1391
[2] #1427
[3] #1428
PS: Looks like some projects are rolling back their winit 0.20.0 update because of issue [1].
See aclysma/skulpin#39
PPS : I have two PRs open :
The text was updated successfully, but these errors were encountered: