linebender/druid · error
Destroying a buffer while it is in use
Error message
Destroying a buffer while it is in use
What it means
Guard panic in Buffer::destroy: the buffer is still marked in-use (attached to a surface and not yet released by the compositor), so destroying it now would violate the wl_buffer protocol and cause protocol errors. It fires when caller code tears down a surface's buffer pool before the compositor has released the buffer.
Solutions
- Wait for the compositor's wl_buffer.release event and clear the in_use flag before calling destroy
- Defer destruction of the buffer to the release callback or drop path
- If the surface is being torn down, let the compositor clean up by dropping the wl_buffer proxy without an explicit destroy-while-attached
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at druid-shell/src/backend/wayland/surfaces/buffers.rs:293 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of linebender/druid@0f8b1195e4 (2026-09-10).
Data as JSON: /api/errors/f9b4944e4e320ecf.
Report an issue: GitHub.
Appendix: source
Thrown at druid-shell/src/backend/wayland/surfaces/buffers.rs:293
}
_ => tracing::warn!("unhandled wayland buffer event: {:?} {:?}", b, event),
}
}));
Buffer { inner, in_use }
}
pub fn attach(&self, wl_surface: &wl::Main<WlSurface>) {
if self.in_use.get() {
panic!("attaching an already in-use surface");
}
self.in_use.set(true);
wl_surface.attach(Some(&self.inner), 0, 0);
}
pub fn destroy(&self) {
if self.in_use.get() {
panic!("Destroying a buffer while it is in use");
}
self.inner.destroy();
}
}
pub struct BufferData<const N: usize> {
buffers: WeakRc<Buffers<N>>,
mmap: Mmap,
}
impl<const N: usize> Deref for BufferData<N> {
type Target = [u8];
fn deref(&self) -> &[u8] {
self.mmap.deref()
}
}
View on GitHub (pinned to 0f8b1195e4)