rust-windowing / rust-windowing/winit
`MonitorHandle` and `VideoMode` can become invalid leading to panics
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 6.2k
- Forks
- 1.3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 9
Description
This is an issue in MonitorHandle and VideoMode. In https://github.com/rust-windowing/winit/pull/3303#discussion_r1436573528 @madsmtm has pointed out that on MacOS these handles are not connected to EventLoop in any way, so they should be fine. We should try and cover all backends and make sure handle method can't and can live after the event loop is exited or otherwise come up with an alternative, e.g. adding a lifetime.
- Rename
VideoModetoVideoModeHandle, similar to other types, to represent that they don't just hold static data: #3328. - Rename it back into
VideoMode, but make it hold only data: https://github.com/rust-windowing/winit/pull/4060. - Both
MonitorHandleandVideoModecan become invalid, e.g. a monitor gets disconnected. So all methods should return an error to handle that. - AFAIK on Linux these types are connected to the
EventLoopso we have to come up with a good solution. This is a similar problem to #3317.
Cc #971, https://github.com/rust-windowing/winit/issues/3102 and #2646.
Original Windows only issue
The MonitorHandle on Windows holds a HMONITOR, which can become invalid if e.g. the monitor is disconnected. Or to be more precise, the Windows documentation recommends to listen to WM_DISPLAYCHANGE, which can potentially invalidate any HMONITOR.
All of the MonitorHandle methods call the GetMonitorInfo function and just unwrap(), which would cause a panic if a HMONITOR has become invalid.
See #3255, which only fixed MonitorHandle::video_modes().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the MonitorHandle and VideoMode implementations across the platform backends, starting with the methods that call GetMonitorInfo and the EventLoop relationships described here. Compare backend behavior when monitors disconnect or the event loop exits, then define coverage that ensures invalid handles are handled without panics and methods report errors consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop-dev, operating-systems
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100