{"record":{"id":"c515caaa30c3e74b","repo":"zed-industries/zed","slug":"internal-error-entered-unreachable-code","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_apple/src/metal_atlas.rs","lineNumber":69,"sourceCode":"    fn insert(\n        &mut self,\n        kind: AtlasTextureKind,\n        size: Size<DevicePixels>,\n        bytes: &[u8],\n    ) -> Result<AtlasTile> {\n        let tile = self.allocate(size, kind).context(\"failed to allocate\")?;\n        let texture = self.texture(tile.texture_id);\n        texture.upload(tile.bounds, bytes);\n        Ok(tile)\n    }\n\n    fn remove(&mut self, tile: AtlasTile) {\n        let id = tile.texture_id;\n\n        let textures = match id.kind {\n            AtlasTextureKind::Monochrome => &mut self.monochrome_textures,\n            AtlasTextureKind::Polychrome => &mut self.polychrome_textures,\n            AtlasTextureKind::Subpixel => unreachable!(),\n        };\n\n        let Some(texture_slot) = textures\n            .textures\n            .iter_mut()\n            .find(|texture| texture.as_ref().is_some_and(|v| v.id == id))\n        else {\n            return;\n        };\n\n        if let Some(mut texture) = texture_slot.take() {\n            texture.allocator.deallocate(tile.tile_id.into());\n            texture.decrement_ref_count();\n            if texture.is_unreferenced() {\n                textures.free_list.push(id.index as usize);\n            } else {\n                *texture_slot = Some(texture);\n            }","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/gpui_apple/src/metal_atlas.rs#L51-L87","documentation":"Metal atlas tile removal dispatches on the atlas texture kind to pick the right texture pool. `AtlasTextureKind::Subpixel` has no corresponding texture list in this atlas implementation, so the code hits an explicit `unreachable!()`. This means a tile with kind Subpixel was handed to an atlas that never allocates Subpixel textures — a caller/atlas mismatch.","triggerScenarios":"Calling `remove(tile)` on a metal atlas with a tile whose `texture_id.kind` is `AtlasTextureKind::Subpixel`, typically because the tile was allocated by a different atlas/path or a kind was added without updating remove.","commonSituations":"Sprite/atlas eviction code that removes tiles regardless of kind, or a new AtlasTextureKind variant introduced without extending every match in metal_atlas.rs.","solutions":["Skip tiles of kind Subpixel in the removal path (or route them to the correct atlas) instead of removing them from this atlas.","Extend the match to handle Subpixel with the correct texture pool if the atlas is supposed to support it.","Verify where the tile originated; only remove tiles that this atlas instance allocated."],"exampleFix":"// before\nAtlasTextureKind::Subpixel => unreachable!(),\n// after\nAtlasTextureKind::Subpixel => return, // subpixel tiles live in a different atlas\n","handlingStrategy":"type-guard","validationCode":"// before removing, ensure this atlas owns the tile kind\nif matches!(tile_texture_kind(&tile), AtlasTextureKind::Subpixel) {\n    return; // not managed by this atlas\n}","typeGuard":"fn is_removable_kind(kind: AtlasTextureKind) -> bool {\n    matches!(kind, AtlasTextureKind::Monochrome | AtlasTextureKind::Polychrome)\n}","tryCatchPattern":null,"preventionTips":["Only remove tiles that the same atlas instance allocated.","When adding an AtlasTextureKind variant, update every match in metal_atlas.rs (allocate and remove).","Keep a single source of truth mapping kinds to texture pools."],"tags":["metal","atlas","gpu","unreachable","panic"],"backgroundTag":"unsupported-enum-value","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}