From ee6d9d51583c9fc7daf71349c321ec01e91c8863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fan=20=C3=96zcan?= <232228291+yorgunkral31@users.noreply.github.com> Date: Tue, 22 Sep 2026 22:22:11 +0300 Subject: [PATCH] fix: drop held drawables when resizing the swap chain On iOS the layer's drawables are invalidated when the app is suspended; holding or presenting them across a resume is undefined. resize() runs with the GPU idled whenever the swap chain is invalidated, so it is the natural point to release the previous generation's references (this also fixes them lingering across ordinary resizes). (cherry picked from commit a19f1377cc5dc002254c9e1d180309c3c90edf72) --- plume_metal.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plume_metal.cpp b/plume_metal.cpp index b670ed3..c47ca6d 100644 --- a/plume_metal.cpp +++ b/plume_metal.cpp @@ -1993,6 +1993,19 @@ namespace plume { bool MetalSwapChain::resize() { MetalAutoreleasePool releasePool; + + // Drop any drawables still held from the previous swap chain generation. + // On iOS the layer's drawables are invalidated when the app is suspended, + // and holding or presenting them across a resume is undefined behavior. + // Callers idle the GPU before resizing, so the references are safe to release. + for (uint32_t i = 0; i < MAX_DRAWABLES; i++) { + MetalDrawable &drawable = drawables[i]; + if (drawable.mtl != nullptr) { + drawable.mtl->release(); + drawable.mtl = nullptr; + } + } + getWindowSize(width, height); if (width == 0 || height == 0) {