mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-30 13:20:06 -04:00
Don't panic when getting refresh rate failed (#2533)
This fixes a crash on macOS when trying to get the monitor refresh rate from the disabled monitor. Co-authored-by: Jet Spark <lixiaopeng.jetspark@bytedance.com> Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
@@ -215,15 +215,18 @@ impl MonitorHandle {
|
||||
pub fn refresh_rate_millihertz(&self) -> Option<u32> {
|
||||
unsafe {
|
||||
let mut display_link = std::ptr::null_mut();
|
||||
assert_eq!(
|
||||
ffi::CVDisplayLinkCreateWithCGDisplay(self.0, &mut display_link),
|
||||
ffi::kCVReturnSuccess
|
||||
);
|
||||
if ffi::CVDisplayLinkCreateWithCGDisplay(self.0, &mut display_link)
|
||||
!= ffi::kCVReturnSuccess
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let time = ffi::CVDisplayLinkGetNominalOutputVideoRefreshPeriod(display_link);
|
||||
ffi::CVDisplayLinkRelease(display_link);
|
||||
|
||||
// This value is indefinite if an invalid display link was specified
|
||||
assert!(time.flags & ffi::kCVTimeIsIndefinite == 0);
|
||||
if time.flags & ffi::kCVTimeIsIndefinite != 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((time.time_scale as i64 / time.time_value * 1000) as u32)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user