{"record":{"id":"2f25a354f5ee561b","repo":"emilk/egui","slug":"vec2b-index-out-of-bounds-index","errorCode":null,"errorMessage":"Vec2b index out of bounds: {index}","messagePattern":"Vec2b index out of bounds: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/emath/src/vec2b.rs","lineNumber":78,"sourceCode":"    }\n}\n\nimpl From<[bool; 2]> for Vec2b {\n    #[inline]\n    fn from([x, y]: [bool; 2]) -> Self {\n        Self { x, y }\n    }\n}\n\nimpl core::ops::Index<usize> for Vec2b {\n    type Output = bool;\n\n    #[inline(always)]\n    fn index(&self, index: usize) -> &bool {\n        match index {\n            0 => &self.x,\n            1 => &self.y,\n            _ => panic!(\"Vec2b index out of bounds: {index}\"),\n        }\n    }\n}\n\nimpl core::ops::IndexMut<usize> for Vec2b {\n    #[inline(always)]\n    fn index_mut(&mut self, index: usize) -> &mut bool {\n        match index {\n            0 => &mut self.x,\n            1 => &mut self.y,\n            _ => panic!(\"Vec2b index out of bounds: {index}\"),\n        }\n    }\n}\n\nimpl core::ops::Not for Vec2b {\n    type Output = Self;\n","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/emath/src/vec2b.rs#L60-L96","documentation":"`Vec2b` (a 2-component boolean vector) implements `Index<usize>` with only 0 (x) and 1 (y) valid; any other index panics with this message. The panic enforces the 2D invariant of the type at the indexing site.","triggerScenarios":"Reading `vec2b[2]` or beyond, usually via a dimension loop that assumes 3 or more axes, or an index computed from external input (config, user selection) applied unchecked.","commonSituations":"Generic layout code iterating axes over the wrong bound; porting from BoolVec3-like types; dynamically chosen axis stored as usize in UI state and later used to index the flag vector.","solutions":["Only use indices 0 and 1; check the index before indexing.","Use the named accessors `vec2b.x` / `vec2b.y` when the component is static.","Iterate with `for axis in 0..2` or convert with `vec2b.to_array()` and index the `[bool; 2]`.","If more flags are needed, use a fixed-size array or a 3-component type instead of Vec2b."],"exampleFix":"// before\nlet flag = vec2b[axis]; // axis may be 2+\n// after\nlet flag = if axis == 0 { vec2b.x } else if axis == 1 { vec2b.y } else { fallback };","handlingStrategy":"type-guard","validationCode":"fn vec2b_get(v: emath::Vec2b, index: usize) -> Option<bool> {\n    match index { 0 => Some(v.x), 1 => Some(v.y), _ => None }\n}","typeGuard":"fn is_vec2b_index(i: usize) -> bool { i < 2 }","tryCatchPattern":"let flag = std::panic::catch_unwind(|| v[index]).unwrap_or(false); // prefer index check","preventionTips":["Read flags via `.x` / `.y` accessors","Bound axis loops to `0..2`","Model axis as an enum with only X and Y variants"],"tags":["rust","panic","emath","index-out-of-bounds","boolean-vector"],"backgroundTag":"index-out-of-bounds","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}