bevyengine/bevy · error

Unsupported MSAA sample count: {samples}

Error message

Unsupported MSAA sample count: {samples}

What it means

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.

Source

Thrown at crates/bevy_render/src/view/mod.rs:260

    Sample2 = 2,
    #[default]
    Sample4 = 4,
    Sample8 = 8,
}

impl Msaa {
    #[inline]
    pub fn samples(&self) -> u32 {
        *self as u32
    }

    pub fn from_samples(samples: u32) -> Self {
        match samples {
            1 => Msaa::Off,
            2 => Msaa::Sample2,
            4 => Msaa::Sample4,
            8 => Msaa::Sample8,
            _ => panic!("Unsupported MSAA sample count: {samples}"),
        }
    }
}

/// Optionally enables a tonemapping shader that attempts to map linear input stimulus into a perceptually uniform image for a given [`Camera`] entity.
///
/// The tonemapping pass lives in `bevy_core_pipeline`. The type is defined in
/// `bevy_render` so render-world code can read it.
#[derive(
    Component, Debug, Hash, Clone, Copy, Reflect, Default, ExtractComponent, PartialEq, Eq,
)]
#[extract_component_filter(With<Camera>)]
#[reflect(Component, Debug, Hash, Default, PartialEq)]
#[extract_app(RenderApp)]
pub enum Tonemapping {
    /// Bypass tonemapping. No color grading, exposure, or dither applies.
    None,
    /// Identity tone curve. [`ColorGrading`], exposure, and [`DebandDither`]

View on GitHub (pinned to 227d3a6c66)

Solutions

  1. Validate the value before calling from_samples and fall back to a supported count (e.g. treat anything above 8 as 8, or 4)
  2. Use the Msaa enum directly in settings instead of a raw integer
  3. If you need to check hardware support, remember the fixed set {1,2,4,8} is the API contract regardless of device

Example fix

// before
let msaa = Msaa::from_samples(settings.msaa_samples); // panics on 16

// after
let msaa = match settings.msaa_samples {
    1 => Msaa::Off,
    2 => Msaa::Sample2,
    8 => Msaa::Sample8,
    _ => Msaa::Sample4,
};
Defensive patterns

Strategy: validation

Validate before calling

// Before calling from_samples:
fn supported_samples(n: u32) -> u32 {
    matches!(n, 1 | 2 | 4 | 8).then_some(n).unwrap_or(4)
}
let msaa = Msaa::from_samples(supported_samples(settings.msaa));

Type guard

fn try_msaa(n: u32) -> Option<Msaa> {
    match n {
        1 => Some(Msaa::Off),
        2 => Some(Msaa::Sample2),
        4 => Some(Msaa::Sample4),
        8 => Some(Msaa::Sample8),
        _ => None,
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of bevyengine/bevy@227d3a6c66 (2026-08-20). Data as JSON: /api/errors/067ee3b5595dd55f. Report an issue: GitHub.