Skip to content

armgit / BUI

Public Imported from GitHub
0

Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI

x11: release the GPU device before destroying the window

nusaturn3c712189cb4d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa900f2..83963f0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ All notable changes to **blenderui** (BUI). The format follows
### Fixed
- **Rust windows:** a dirty window with a pending frame request waits for that frame instead of a 0 ms timer, so `requestAnimationFrame` callbacks run once per frame.
- **X11:** a frame callback that closes its window no longer renders into the closed window.
+- **X11:** a window that closes while its GPU device starts releases the device before the X window is destroyed (`BUI_raster_gpu_release`), so Mesa no longer prints `failed to create drawable`.
## [0.4.1] - 2026-11-06
diff --git a/gpu/include/GPU_raster.h b/gpu/include/GPU_raster.h
index 4820485..034a6f0 100644
--- a/gpu/include/GPU_raster.h
+++ b/gpu/include/GPU_raster.h
@@ -315,6 +315,9 @@ int BUI_raster_gpu_poll(BuiRaster *r);
/* 1 while attach() still creates the device. A host polls until it is 0, so an idle window
* also switches over. */
int BUI_raster_gpu_pending(const BuiRaster *r);
+/* Frees the GPU device and waits for a device that is still starting. Call it before the window
+ * is destroyed. The raster draws on the CPU again from its next frame. */
+void BUI_raster_gpu_release(BuiRaster *r);
int BUI_raster_is_gpu(const BuiRaster *r);
/* Whether new windows use the GPU: BUI_gpu_set_default(), overridden by the
* BUI_GPU environment variable (1/0). Off by default. */
diff --git a/gpu/intern/gpu_raster.c b/gpu/intern/gpu_raster.c
index c498a5b..e2e3eb7 100644
--- a/gpu/intern/gpu_raster.c
+++ b/gpu/intern/gpu_raster.c
@@ -194,8 +194,7 @@ void BUI_raster_free(BuiRaster *r)
if (!r) {
return;
}
- bui_gpu_free(r->gpu);
- bui_gpu_free(r->gpu_pending);
+ BUI_raster_gpu_release(r);
BUI_raster_free(r->scratch);
free(r->pix);
free(r->prev);
@@ -306,6 +305,17 @@ int BUI_raster_gpu_poll(BuiRaster *r)
return sw;
}
+void BUI_raster_gpu_release(BuiRaster *r)
+{
+ bui_gpu_free(r->gpu_pending);
+ r->gpu_pending = NULL;
+ if (r->gpu) {
+ bui_gpu_free(r->gpu);
+ r->gpu = NULL;
+ r->w = r->h = 0; /* the next frame allocates the CPU frame */
+ }
+}
+
int BUI_raster_gpu_pending(const BuiRaster *r)
{
return r->gpu_pending != NULL;
diff --git a/kit/intern/kit_window_x11.c b/kit/intern/kit_window_x11.c
index 9c585e4..6a4f70c 100644
--- a/kit/intern/kit_window_x11.c
+++ b/kit/intern/kit_window_x11.c
@@ -534,6 +534,7 @@ static void close_window(BKWindow *win)
if (!win->xid) {
return;
}
+ BUI_raster_gpu_release(win->raster); /* the GL context uses the window */
XDestroyWindow(g_dpy, win->xid);
XFlush(g_dpy);
win->xid = 0;