emilk/egui · critical
Failed to create staging buffer for vertex data. Vertex coun
Error message
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) What it means
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.
Source
Thrown at crates/egui-wgpu/src/renderer.rs:1079
let required_vertex_buffer_size =
(core::mem::size_of::<Vertex>() * vertex_count) as u64;
if self.vertex_buffer.capacity < required_vertex_buffer_size {
// Resize vertex buffer if needed.
self.vertex_buffer.capacity =
(self.vertex_buffer.capacity * 2).at_least(required_vertex_buffer_size);
self.vertex_buffer.buffer =
create_vertex_buffer(device, self.vertex_buffer.capacity);
}
let vertex_buffer_staging = queue.write_buffer_with(
&self.vertex_buffer.buffer,
0,
#[expect(clippy::unwrap_used)] // Checked above
NonZeroU64::new(required_vertex_buffer_size).unwrap(),
);
let Some(mut vertex_buffer_staging) = vertex_buffer_staging else {
panic!(
"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)",
self.vertex_buffer.buffer.size(),
self.vertex_buffer.capacity
);
};
let mut vertex_offset = 0;
for epaint::ClippedPrimitive { primitive, .. } in paint_jobs {
match primitive {
Primitive::Mesh(mesh) => {
let size = mesh.vertices.len() * core::mem::size_of::<Vertex>();
let slice = vertex_offset..(size + vertex_offset);
vertex_buffer_staging
.slice(slice.clone())
.copy_from_slice(bytemuck::cast_slice(&mesh.vertices));
self.vertex_buffer.slices.push(slice);
vertex_offset += size;
}View on GitHub (pinned to 441971a776)
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.
Defensive patterns
Strategy: validation
Validate before calling
let limits = adapter.limits();
let required = (vertex_count as u64) * std::mem::size_of::<epaint::Vertex>() as u64;
assert!(required <= limits.max_buffer_size, "egui vertex buffer {required} exceeds max_buffer_size {}", limits.max_buffer_size); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Failed to create staging buffer for index data. Index count:
- Failed to create image
- Failed to create render state
- You must call .update_buffers() before .render()
- Tried to update a texture that has not been allocated yet.
AI-assisted analysis of emilk/egui@441971a776 (2026-09-12).
Data as JSON: /api/errors/4ecae8d074edb447.
Report an issue: GitHub.