{"record":{"id":"4ecae8d074edb447","repo":"emilk/egui","slug":"failed-to-create-staging-buffer-for-vertex-data-v","errorCode":null,"errorMessage":"Failed to create staging buffer for vertex data. Vertex count: {vertex_count}. Required vertex buffer size: {required_vertex_buffer_size}. Actual size {} and capacity: {} (bytes)","messagePattern":"Failed to create staging buffer for vertex data\\. Vertex count: (.+?)\\. Required vertex buffer size: (.+?)\\. Actual size (.+?) and capacity: (.+?) \\(bytes\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/egui-wgpu/src/renderer.rs","lineNumber":1079,"sourceCode":"            let required_vertex_buffer_size =\n                (core::mem::size_of::<Vertex>() * vertex_count) as u64;\n            if self.vertex_buffer.capacity < required_vertex_buffer_size {\n                // Resize vertex buffer if needed.\n                self.vertex_buffer.capacity =\n                    (self.vertex_buffer.capacity * 2).at_least(required_vertex_buffer_size);\n                self.vertex_buffer.buffer =\n                    create_vertex_buffer(device, self.vertex_buffer.capacity);\n            }\n\n            let vertex_buffer_staging = queue.write_buffer_with(\n                &self.vertex_buffer.buffer,\n                0,\n                #[expect(clippy::unwrap_used)] // Checked above\n                NonZeroU64::new(required_vertex_buffer_size).unwrap(),\n            );\n\n            let Some(mut vertex_buffer_staging) = vertex_buffer_staging else {\n                panic!(\n                    \"Failed to create staging buffer for vertex data. Vertex count: {vertex_count}. Required vertex buffer size: {required_vertex_buffer_size}. Actual size {} and capacity: {} (bytes)\",\n                    self.vertex_buffer.buffer.size(),\n                    self.vertex_buffer.capacity\n                );\n            };\n\n            let mut vertex_offset = 0;\n            for epaint::ClippedPrimitive { primitive, .. } in paint_jobs {\n                match primitive {\n                    Primitive::Mesh(mesh) => {\n                        let size = mesh.vertices.len() * core::mem::size_of::<Vertex>();\n                        let slice = vertex_offset..(size + vertex_offset);\n                        vertex_buffer_staging\n                            .slice(slice.clone())\n                            .copy_from_slice(bytemuck::cast_slice(&mesh.vertices));\n                        self.vertex_buffer.slices.push(slice);\n                        vertex_offset += size;\n                    }","sourceCodeStart":1061,"sourceCodeEnd":1097,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/egui-wgpu/src/renderer.rs#L1061-L1097","documentation":"The egui-wgpu renderer allocates a staging buffer for vertex data each frame. If wgpu fails to create that staging buffer (usually because the required size exceeds device buffer limits or memory allocation fails), the renderer panics, reporting the vertex count, required size, and the current buffer's actual size and capacity.","triggerScenarios":"A frame's tessellation produces `vertex_count` vertices whose `required_vertex_buffer_size` cannot be satisfied by `device.create_buffer`, making `vertex_buffer_staging` `None` — e.g. exceeding `max_buffer_size` limits or GPU OOM.","commonSituations":"Very large/immediate-mode UIs drawing tens of thousands of primitives (dense grids, images, long unclipped lists); devices with restrictive buffer limits; using `Limits::downlevel_defaults()` or custom reduced limits with egui.","solutions":["Raise the wgpu device `Limits` (particularly `max_buffer_size`) when creating the device.","Reduce per-frame vertex load: clip/virtualize content, fewer rounded rects/shadows/text glyphs visible at once.","Verify adapter selection — a downlevel or software adapter may impose small limits; pick a full backend when available.","Compare the panic's required size with your configured `max_buffer_size` and adjust limits or content accordingly."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let limits = adapter.limits();\nlet required = (vertex_count as u64) * std::mem::size_of::<epaint::Vertex>() as u64;\nassert!(required <= limits.max_buffer_size, \"egui vertex buffer {required} exceeds max_buffer_size {}\", limits.max_buffer_size);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use default (or explicitly raised) wgpu Limits when requesting the device for egui.","Reduce visible UI density: clip scroll areas, avoid unbounded numbers of shadows/rounded rects.","Profile vertex counts on the weakest supported GPU/software adapter.","Split extremely large UIs across frames or passes to cap per-frame buffer requirements."],"tags":["wgpu","gpu","buffer-allocation","panic"],"backgroundTag":"resource-not-found","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}