From 416f6004cef036dad7f32a5f7b5a1a23e98c0beb Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Wed, 2 Dec 2026 19:51:44 +0200 Subject: [PATCH] fix: crash on window close from double-release of shader blobs The context destructor explicitly Release()d each ID3DBlob and then shader_blobs.clear() ran the unique_ptr default deleter, which called delete on the already-released (destroyed) COM objects, crashing the process. Use a custom deleter for the shader blob vector that calls ID3DBlob::Release(), and drop the explicit release loop. --- src/ruis/render/directx/context.cpp | 7 +------ src/ruis/render/directx/context.hpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/ruis/render/directx/context.cpp b/src/ruis/render/directx/context.cpp index 2ad8dd9..3237d7d 100644 --- a/src/ruis/render/directx/context.cpp +++ b/src/ruis/render/directx/context.cpp @@ -126,12 +126,7 @@ context::~context() } this->pipelines.clear(); - // release the compiled shader blobs - for (auto& blob : this->shader_blobs) { - if (blob != nullptr) { - blob->Release(); - } - } + // release the compiled shader blobs (the vector elements invoke ID3DBlob::Release()) this->shader_blobs.clear(); // the screen depth diff --git a/src/ruis/render/directx/context.hpp b/src/ruis/render/directx/context.hpp index 384447b..172b288 100644 --- a/src/ruis/render/directx/context.hpp +++ b/src/ruis/render/directx/context.hpp @@ -43,6 +43,17 @@ class texture_2d; class texture_depth; class index_buffer; +// com unique_ptr for ID3DBlob: the COM object is released (not deleted) +struct shader_blob_deleter { + void operator()(ID3DBlob* blob) const noexcept + { + if (blob != nullptr) { + blob->Release(); + } + } +}; +using shader_blob_ptr = std::unique_ptr; + // a key identifying a unique ID3D12PipelineState (PSO). The pipeline is // independent of the particular vertex array, since the vertex input layout // depends only on the shader (determining the attributes), and the actual @@ -230,7 +241,7 @@ class context : public ruis::render::context std::unordered_map pipelines; // the shader blobs compiled for the pipelines created this frame // (they must stay alive while their PSOs are alive) - std::vector> shader_blobs; + std::vector shader_blobs; // ---- current frame state ---- bool frame_begun = false;