{"record":{"id":"567ffedaaf7a23a6","repo":"linebender/druid","slug":"didn-t-get-any-modes","errorCode":null,"errorMessage":"didn't get any modes","messagePattern":"didn't get any modes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"druid-shell/src/backend/x11/util.rs","lineNumber":28,"sourceCode":"use x11rb::errors::ReplyError;\nuse x11rb::protocol::randr::{ConnectionExt, ModeFlag};\nuse x11rb::protocol::render::{self, ConnectionExt as _};\nuse x11rb::protocol::xproto::{Screen, Visualid, Visualtype, Window};\nuse x11rb::xcb_ffi::XCBConnection;\n\n// See: https://github.com/rtbo/rust-xcb/blob/master/examples/randr_screen_modes.rs\npub fn refresh_rate(conn: &Rc<XCBConnection>, window_id: Window) -> Option<f64> {\n    let try_refresh_rate = || -> Result<f64, Error> {\n        let reply = conn.randr_get_screen_resources(window_id)?.reply()?;\n\n        // TODO(x11/render_improvements): Figure out a more correct way of getting the screen's refresh rate.\n        //     Or maybe we don't even need this function if I figure out a better way to schedule redraws?\n        //     Assuming the first mode is the one we want to use. This is probably a bug on some setups.\n        //     Any better way to find the correct one?\n        reply\n            .modes\n            .first()\n            .ok_or_else(|| anyhow!(\"didn't get any modes\"))\n            .and_then(|mode_info| {\n                let flags = mode_info.mode_flags;\n                let vtotal = {\n                    let mut val = mode_info.vtotal;\n                    if (flags & u32::from(ModeFlag::DOUBLE_SCAN)) != 0 {\n                        val *= 2;\n                    }\n                    if (flags & u32::from(ModeFlag::INTERLACE)) != 0 {\n                        val /= 2;\n                    }\n                    val\n                };\n\n                if vtotal != 0 && mode_info.htotal != 0 {\n                    Ok((mode_info.dot_clock as f64) / (vtotal as f64 * mode_info.htotal as f64))\n                } else {\n                    Err(anyhow!(\"got nonsensical mode values\"))\n                }","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/linebender/druid/blob/0f8b1195e4e073f9597f2865299c3d18f8e4005f/druid-shell/src/backend/x11/util.rs#L10-L46","documentation":"Thrown by the public util::refresh_rate helper when the X RandR reply contains an empty modes list for the requested output/crtc. Refresh rate is computed from the first display mode, so with no modes reported there is no rate to derive, and the function fails instead of returning a bogus value.","triggerScenarios":"Calling refresh_rate on a system where the RandR GetMonitors/GetCrtcInfo reply has zero modes — disconnected or phantom outputs, headless servers (Xvfb has no RandR modes by default), or outputs attached to a disabled CRTC.","commonSituations":"Running inside Xvfb or a nested server without realistic mode data; laptops with a lid-closed/disabled external output queried for its refresh rate; broken driver setups where RandR reports outputs with no mode lines.","solutions":["Fall back to a sensible default (e.g. 60.0) when refresh_rate returns Err, rather than propagating the failure.","Query a connected/enabled output instead of the first output reported by RandR (filter RandR outputs with connection == Connected).","Use a server with real mode data (Xorg with a real driver or Xvfb configured with a screen mode) for accurate rates."],"exampleFix":"// before\nlet rate = refresh_rate(conn, screen_num)?;\n// after\nlet rate = refresh_rate(conn, screen_num).unwrap_or(60.0);","handlingStrategy":"fallback","validationCode":"let modes_len = conn.randr().get_screen_resources(screen.root)?.reply?.modes.len();\nlet has_modes = modes_len > 0;","typeGuard":null,"tryCatchPattern":"let rate = match refresh_rate(&conn, screen_num) {\n    Ok(r) => r,\n    Err(_) => 60.0, // safe default when RandR reports no modes\n};","preventionTips":["Only query refresh rate for outputs with an active CRTC/connected state.","Default to 60 Hz (or an app-configured value) when rate detection fails.","In headless/CI environments, don't rely on RandR-derived rates at all."],"tags":["x11","randr","empty-result-set"],"backgroundTag":"empty-result-set","analyzedSha":"0f8b1195e4e073f9597f2865299c3d18f8e4005f","analyzedAt":"2026-09-10T14:27:34.582Z","contentChangedAt":"2026-09-10T14:27:34.582Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}