{"record":{"id":"196c5a7f66a18505","repo":"zed-industries/zed","slug":"just-ensured-the-render-target-exists","errorCode":null,"errorMessage":"just ensured the render target exists","messagePattern":"just ensured the render target exists","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_apple/src/metal_renderer.rs","lineNumber":641,"sourceCode":"\n        let needs_new_target = self.headless_render_target.as_ref().is_none_or(|texture| {\n            texture.width() != size.width.0 as u64 || texture.height() != size.height.0 as u64\n        });\n        if needs_new_target {\n            let texture_descriptor = metal::TextureDescriptor::new();\n            texture_descriptor.set_width(size.width.0 as u64);\n            texture_descriptor.set_height(size.height.0 as u64);\n            texture_descriptor.set_pixel_format(MTLPixelFormat::BGRA8Unorm);\n            texture_descriptor.set_usage(\n                metal::MTLTextureUsage::RenderTarget | metal::MTLTextureUsage::ShaderRead,\n            );\n            texture_descriptor.set_storage_mode(metal::MTLStorageMode::Private);\n            self.headless_render_target = Some(self.device.new_texture(&texture_descriptor));\n        }\n        let target_texture = self\n            .headless_render_target\n            .clone()\n            .expect(\"just ensured the render target exists\");\n\n        let command_buffer = self.render_frame(scene, &target_texture, size)?;\n\n        // Commit without waiting, mirroring presentation to a real window where\n        // the CPU doesn't block on the GPU.\n        command_buffer.commit();\n        Ok(())\n    }\n\n    fn draw_primitives_to_texture(\n        &mut self,\n        scene: &Scene,\n        instance_bindings: &InstanceBindings,\n        writer: &mut InstanceBufferWriter,\n        texture: &metal::TextureRef,\n        viewport_size: Size<DevicePixels>,\n    ) -> Result<metal::CommandBuffer> {\n        let command_queue = self.command_queue.clone();","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/gpui_apple/src/metal_renderer.rs#L623-L659","documentation":"In render_scene's headless path, the render target texture is created just above when needs_new_target was true, so retrieving it must succeed. The expect firing means the target creation silently failed or the code path skipped creation while still proceeding to render — an internal logic bug.","triggerScenarios":"Thrown at crates/gpui_apple/src/metal_renderer.rs:641 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the texture creation call (newTextureWithDescriptor) actually succeeded","Ensure the created texture is stored in headless_render_target before use","Check for size-zero requests slipping past the needs_new_target check"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}