{"record":{"id":"0b41c12350e811d3","repo":"zed-industries/zed","slug":"directx-instance-range-exceeds-the-buffer","errorCode":null,"errorMessage":"DirectX instance range exceeds the {} buffer","messagePattern":"DirectX instance range exceeds the (.+?) buffer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_windows/src/directx_renderer.rs","lineNumber":1119,"sourceCode":"        );\n        unsafe {\n            device_context.PSSetSamplers(0, Some(sampler));\n            device_context.VSSetShaderResources(0, Some(texture));\n            device_context.PSSetShaderResources(0, Some(texture));\n\n            device_context.DrawInstanced(4, instance_count, 0, 0);\n        }\n        Ok(())\n    }\n\n    fn draw_range(\n        &self,\n        device_context: &ID3D11DeviceContext,\n        batch_params_buffer: &ID3D11Buffer,\n        first_instance: u32,\n        instance_count: u32,\n    ) -> Result<()> {\n        anyhow::ensure!(\n            first_instance as usize + instance_count as usize <= self.buffer_size,\n            \"DirectX instance range exceeds the {} buffer\",\n            self.label\n        );\n        update_batch_start(device_context, batch_params_buffer, first_instance)?;\n        set_pipeline_state(\n            device_context,\n            slice::from_ref(&self.view),\n            D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,\n            &self.vertex,\n            &self.fragment,\n            &self.blend_state,\n        );\n        unsafe {\n            device_context.DrawInstanced(4, instance_count, 0, 0);\n        }\n        Ok(())\n    }","sourceCodeStart":1101,"sourceCodeEnd":1137,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/gpui_windows/src/directx_renderer.rs#L1101-L1137","documentation":"Guard in `draw_range`: `first_instance + instance_count` would run past the end of the allocated D3D11 instance buffer, so DrawInstanced would read out of bounds; the draw is rejected. Indicates an internal batching/offset bookkeeping bug rather than bad user input.","triggerScenarios":"Thrown at crates/gpui_windows/src/directx_renderer.rs:1119 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix upstream batch computation so ranges always fit the uploaded buffer.","Add assertions where instance ranges are computed to catch misbookkeeping early.","Re-upload the buffer if the previous frame's data was smaller than the requested range.","Log the buffer size vs requested range to locate the off-by-N bug."],"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-14T00:17:10.932Z"}