zed-industries/zed · error

just ensured the render target exists

Error message

just ensured the render target exists

What it means

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.

Source

Thrown at crates/gpui_apple/src/metal_renderer.rs:641

        let needs_new_target = self.headless_render_target.as_ref().is_none_or(|texture| {
            texture.width() != size.width.0 as u64 || texture.height() != size.height.0 as u64
        });
        if needs_new_target {
            let texture_descriptor = metal::TextureDescriptor::new();
            texture_descriptor.set_width(size.width.0 as u64);
            texture_descriptor.set_height(size.height.0 as u64);
            texture_descriptor.set_pixel_format(MTLPixelFormat::BGRA8Unorm);
            texture_descriptor.set_usage(
                metal::MTLTextureUsage::RenderTarget | metal::MTLTextureUsage::ShaderRead,
            );
            texture_descriptor.set_storage_mode(metal::MTLStorageMode::Private);
            self.headless_render_target = Some(self.device.new_texture(&texture_descriptor));
        }
        let target_texture = self
            .headless_render_target
            .clone()
            .expect("just ensured the render target exists");

        let command_buffer = self.render_frame(scene, &target_texture, size)?;

        // Commit without waiting, mirroring presentation to a real window where
        // the CPU doesn't block on the GPU.
        command_buffer.commit();
        Ok(())
    }

    fn draw_primitives_to_texture(
        &mut self,
        scene: &Scene,
        instance_bindings: &InstanceBindings,
        writer: &mut InstanceBufferWriter,
        texture: &metal::TextureRef,
        viewport_size: Size<DevicePixels>,
    ) -> Result<metal::CommandBuffer> {
        let command_queue = self.command_queue.clone();

View on GitHub (pinned to f4178619ac)

Solutions

  1. Verify the texture creation call (newTextureWithDescriptor) actually succeeded
  2. Ensure the created texture is stored in headless_render_target before use
  3. Check for size-zero requests slipping past the needs_new_target check
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/gpui_apple/src/metal_renderer.rs:641 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/196c5a7f66a18505. Report an issue: GitHub.