{"record":{"id":"76dcf9de2bba3f1d","repo":"gfx-rs/wgpu","slug":"plane-plane-is-not-valid-for-self","errorCode":null,"errorMessage":"plane {plane} is not valid for {self:?}","messagePattern":"plane (.+?) is not valid for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-types/src/texture/format.rs","lineNumber":547,"sourceCode":"\n    /// Returns the number of planes a multi-planar format has.\n    #[must_use]\n    pub fn planes(&self) -> Option<u32> {\n        match *self {\n            Self::NV12 => Some(2),\n            Self::P010 => Some(2),\n            _ => None,\n        }\n    }\n\n    /// Returns the subsampling factor for the indicated plane of a multi-planar format.\n    #[must_use]\n    pub fn subsampling_factors(&self, plane: Option<u32>) -> (u32, u32) {\n        match *self {\n            Self::NV12 | Self::P010 => match plane {\n                Some(0) => (1, 1),\n                Some(1) => (2, 2),\n                Some(plane) => unreachable!(\"plane {plane} is not valid for {self:?}\"),\n                None => unreachable!(\"the plane must be specified for multi-planar formats\"),\n            },\n            _ => (1, 1),\n        }\n    }\n\n    /// Returns a [TextureChannel] with the bits set where the texture format contains\n    /// the respective channels.\n    ///\n    /// # Example\n    /// ```rust\n    /// # use wgpu_types::{TextureFormat, TextureChannel};\n    ///\n    /// // `Rgba` has a `red`, `green`, `blue` and `alpha` channel!\n    /// assert!(TextureFormat::Rgba8Unorm.channels().contains(TextureChannel::RGBA));\n    ///\n    /// // `Rg` hasn't got an alpha channel...\n    /// assert!(!TextureFormat::Rg8Unorm.channels().contains(TextureChannel::ALPHA));","sourceCodeStart":529,"sourceCodeEnd":565,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-types/src/texture/format.rs#L529-L565","documentation":"`TextureFormat::subsampling_factors(plane)` returns the chroma subsampling factor for a given plane index. For multi-planar formats (NV12, P010) only planes 0 and 1 exist; requesting any other plane index panics with this message because there is no defined subsampling for it.","triggerScenarios":"Calling `format.subsampling_factors(Some(n))` where format is NV12 or P010 and n >= 2 (e.g. iterating planes 0..format.plane_count() incorrectly, or hardcoding plane indices).","commonSituations":"Video decode/encode pipelines iterating planes with a wrong count; copying code between single-planar and multi-planar handling; misreading plane_count for NV12/P010 (which is 2).","solutions":["Only request planes 0 or 1 for NV12/P010 — derive the loop bound from `format.plane_count()`","For non-multi-planar formats pass `None`, which returns (1,1)","Add a bounds check or match on the format before querying plane-specific properties"],"exampleFix":"// before\nfor plane in 0..3 {\n    let (fx, fy) = format.subsampling_factors(Some(plane));\n}\n// after\nfor plane in 0..format.plane_count() {\n    let (fx, fy) = format.subsampling_factors(Some(plane as u32));\n}","handlingStrategy":"validation","validationCode":"fn valid_plane(format: wgpu::TextureFormat, plane: u32) -> bool {\n    plane < format.plane_count() as u32\n}","typeGuard":"fn plane_in_range(format: wgpu::TextureFormat, plane: u32) -> Option<u32> {\n    (plane < format.plane_count() as u32).then_some(plane)\n}","tryCatchPattern":null,"preventionTips":["Derive plane loop bounds from format.plane_count(), never hardcode","Remember NV12/P010 have exactly 2 planes","Centralize per-plane property queries in one helper that validates the index"],"tags":["wgpu-types","texture-format","plane-index","panic","video"],"backgroundTag":"invalid-plane-index","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}