{"record":{"id":"067ee3b5595dd55f","repo":"bevyengine/bevy","slug":"unsupported-msaa-sample-count-samples","errorCode":null,"errorMessage":"Unsupported MSAA sample count: {samples}","messagePattern":"Unsupported MSAA sample count: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_render/src/view/mod.rs","lineNumber":260,"sourceCode":"    Sample2 = 2,\n    #[default]\n    Sample4 = 4,\n    Sample8 = 8,\n}\n\nimpl Msaa {\n    #[inline]\n    pub fn samples(&self) -> u32 {\n        *self as u32\n    }\n\n    pub fn from_samples(samples: u32) -> Self {\n        match samples {\n            1 => Msaa::Off,\n            2 => Msaa::Sample2,\n            4 => Msaa::Sample4,\n            8 => Msaa::Sample8,\n            _ => panic!(\"Unsupported MSAA sample count: {samples}\"),\n        }\n    }\n}\n\n/// Optionally enables a tonemapping shader that attempts to map linear input stimulus into a perceptually uniform image for a given [`Camera`] entity.\n///\n/// The tonemapping pass lives in `bevy_core_pipeline`. The type is defined in\n/// `bevy_render` so render-world code can read it.\n#[derive(\n    Component, Debug, Hash, Clone, Copy, Reflect, Default, ExtractComponent, PartialEq, Eq,\n)]\n#[extract_component_filter(With<Camera>)]\n#[reflect(Component, Debug, Hash, Default, PartialEq)]\n#[extract_app(RenderApp)]\npub enum Tonemapping {\n    /// Bypass tonemapping. No color grading, exposure, or dither applies.\n    None,\n    /// Identity tone curve. [`ColorGrading`], exposure, and [`DebandDither`]","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/bevyengine/bevy/blob/227d3a6c661b3bdf3020d3e8290b5a6ffd0226f7/crates/bevy_render/src/view/mod.rs#L242-L278","documentation":"Msaa::from_samples maps exactly 1, 2, 4 and 8 to the Msaa enum variants (Off, Sample2, Sample4, Sample8); there is no Sample16 variant, so any other value (0, 3, 6, 16, ...) panics. The function assumes the caller passes a hardware-supported MSAA sample count.","triggerScenarios":"Msaa::from_samples(n) where n is not in {1,2,4,8} — commonly 16 from a graphics settings menu, or a computed/serialized sample count (0, 6) from a config file or CLI flag.","commonSituations":"Loading graphics presets from disk where a user edited 'msaa: 16'; deserializing old settings; code that multiplies or scales sample counts and lands on unsupported values.","solutions":["Validate the value before calling from_samples and fall back to a supported count (e.g. treat anything above 8 as 8, or 4)","Use the Msaa enum directly in settings instead of a raw integer","If you need to check hardware support, remember the fixed set {1,2,4,8} is the API contract regardless of device"],"exampleFix":"// before\nlet msaa = Msaa::from_samples(settings.msaa_samples); // panics on 16\n\n// after\nlet msaa = match settings.msaa_samples {\n    1 => Msaa::Off,\n    2 => Msaa::Sample2,\n    8 => Msaa::Sample8,\n    _ => Msaa::Sample4,\n};","handlingStrategy":"validation","validationCode":"// Before calling from_samples:\nfn supported_samples(n: u32) -> u32 {\n    matches!(n, 1 | 2 | 4 | 8).then_some(n).unwrap_or(4)\n}\nlet msaa = Msaa::from_samples(supported_samples(settings.msaa));","typeGuard":"fn try_msaa(n: u32) -> Option<Msaa> {\n    match n {\n        1 => Some(Msaa::Off),\n        2 => Some(Msaa::Sample2),\n        4 => Some(Msaa::Sample4),\n        8 => Some(Msaa::Sample8),\n        _ => None,\n    }\n}","tryCatchPattern":null,"preventionTips":["Never feed unvalidated ints from configs/UI into Msaa::from_samples","Store the Msaa enum (not a raw count) in settings files and clamp on load","Treat {1,2,4,8} as the whole supported set — there is no 16x variant"],"tags":["bevy","msaa","graphics-settings","validation","panic"],"backgroundTag":"invalid-config-value","analyzedSha":"227d3a6c661b3bdf3020d3e8290b5a6ffd0226f7","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}