{"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":"        let vertex = {\n            let raw_shader = RawShaderBytes::new(shader_module, ShaderTarget::Vertex)?;\n            create_vertex_shader(device, raw_shader.as_bytes())?\n        };\n        let fragment = {\n            let raw_shader = RawShaderBytes::new(shader_module, ShaderTarget::Fragment)?;\n            create_fragment_shader(device, raw_shader.as_bytes())?\n        };\n        let buffer = create_buffer(device, std::mem::size_of::<T>(), buffer_size)?;\n        let view = create_buffer_view(device, &buffer)?;\n\n        Ok(PipelineState {\n            label,\n            vertex,\n            fragment,\n            buffer,\n            buffer_size,\n            view,\n            blend_state,\n            _marker: std::marker::PhantomData,\n        })\n    }\n\n    fn update_buffer(\n        &mut self,\n        device: &ID3D11Device,\n        device_context: &ID3D11DeviceContext,\n        data: &[T],\n    ) -> Result<()> {\n        if self.buffer_size < data.len() {\n            let element_size = std::mem::size_of::<T>();\n            let required_size = std::mem::size_of_val(data);\n            anyhow::ensure!(\n                required_size <= MAX_INSTANCE_BUFFER_SIZE,\n                \"{} buffer needs {required_size} bytes, above the maximum of {MAX_INSTANCE_BUFFER_SIZE}\",\n                self.label\n            );","sourceCodeStart":1101,"sourceCodeEnd":1137,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/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":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}