{"record":{"id":"61aa1abf12194333","repo":"a-b-street/abstreet","slug":"can-t-take-screenshots-of-dims-when-the-window-is-only","errorCode":null,"errorMessage":"Can't take screenshots of dims {:?} when the window is only {:?}","messagePattern":"Can't take screenshots of dims (.+?) when the window is only (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"widgetry/src/tools/screenshot.rs","lineNumber":15,"sourceCode":"use abstutil::Timer;\n\nuse crate::runner::State;\nuse crate::{Prerender, ScreenDims, SharedAppState};\n\n/// Take a screenshot of the entire canvas, tiling it based on the window's width and height.\npub(crate) fn screenshot_everything<A: 'static + SharedAppState>(\n    state: &mut State<A>,\n    dir_path: &str,\n    prerender: &Prerender,\n    zoom: f64,\n    dims: ScreenDims,\n) -> anyhow::Result<()> {\n    if dims.width > state.canvas.window_width || dims.height > state.canvas.window_height {\n        bail!(\n            \"Can't take screenshots of dims {:?} when the window is only {:?}\",\n            dims,\n            state.canvas.get_window_dims()\n        );\n    }\n\n    let mut timer = Timer::new(\"capturing screen\");\n    let num_tiles_x = (state.canvas.map_dims.0 * zoom / dims.width).ceil() as usize;\n    let num_tiles_y = (state.canvas.map_dims.1 * zoom / dims.height).ceil() as usize;\n    let orig_zoom = state.canvas.cam_zoom;\n    let orig_x = state.canvas.cam_x;\n    let orig_y = state.canvas.cam_y;\n\n    timer.start_iter(\"capturing images\", num_tiles_x * num_tiles_y);\n    state.canvas.cam_zoom = zoom;\n    fs_err::create_dir_all(dir_path)?;\n\n    // See https://github.com/a-b-street/abstreet/issues/671 for context. Some maps are so large","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/widgetry/src/tools/screenshot.rs#L1-L33","documentation":"screenshot_everything captures the window contents at the requested ScreenDims; if the requested dimensions exceed the actual canvas window size, offscreen rendering would clip the screenshot, so the library refuses up front with this bail. It is a guard against producing cropped/invalid screenshots. The message echoes the requested dims and the actual window dims.","triggerScenarios":"Calling screenshot_everything (via run) with a dims argument whose width or height is greater than state.canvas.window_width / window_height — typically when the CLI-specified screenshot size exceeds the window size the app was started with.","commonSituations":"Passing --dims larger than the default window without raising the window size; running in a smaller monitor/virtual display; automated screenshot harness reusing a fixed window size with bigger desired output.","solutions":["Start the app with a window at least as large as the requested screenshot dims (increase the window/canvas size)","Lower the requested dims to fit within the current window dims","If supported, use a prerendered/offscreen render path at higher resolution instead of window capture","Check state.canvas.get_window_dims() first and clamp the requested dims"],"exampleFix":"// before\nscreenshot_everything(dir, &prerender, zoom, ScreenDims::new(3840.0, 2160.0))?;\n// after\nlet dims = ScreenDims::new(3840.0, 2160.0);\nlet (w, h) = state.canvas.get_window_dims();\nlet dims = ScreenDims::new(dims.width.min(w), dims.height.min(h));\nscreenshot_everything(dir, &prerender, zoom, dims)?;","handlingStrategy":"validation","validationCode":"let (win_w, win_h) = state.canvas.get_window_dims();\nassert!(dims.width <= win_w && dims.height <= win_h, \"screenshot dims exceed window\");","typeGuard":"fn dims_fit(dims: &ScreenDims, canvas: &Canvas) -> bool {\n    dims.width <= canvas.window_width && dims.height <= canvas.window_height\n}","tryCatchPattern":"match screenshot_everything(dir, &prerender, zoom, dims) {\n    Ok(()) => (),\n    Err(e) => eprintln!(\"screenshot skipped: {e}\"),\n}","preventionTips":["Clamp requested dims to canvas.get_window_dims() before capturing","Size the window to the desired screenshot resolution at startup","Keep automated screenshot harness window sizes in sync with requested dims","Prefer prerendered/offscreen capture for high-resolution output"],"tags":["screenshot","dimensions","canvas","widgetry"],"backgroundTag":"value-out-of-range","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}