From a8a56cb47ede0039988abab4a2e17e5be2a48c5c Mon Sep 17 00:00:00 2001 From: adrianmjim <11887815+adrianmjim@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:19:01 +0100 Subject: [PATCH 1/2] test: d3d12test::Ref owns its pointer alone: move only, and `ref = {}` releases (TEST-REF-MOVE-ONLY) Ref had a destructor but no copy or move members of its own. So: - `ref = {}` copied a null pointer over the held one and never called Release (the slot 133 resource in #1558's new test stayed alive and kept the whole device, 63 objects in the validation layer's vkDestroyDevice report); - a copy, including the one std::vector makes when it grows (no implicit move with a user-declared destructor), would Release twice. Copying is now deleted and moving transfers the pointer; move assignment releases the old one, so `ref = {}` does what it reads as. Every test that includes the header builds unchanged: none copies a Ref. --- runtime/test/d3d12_test_shaders.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/runtime/test/d3d12_test_shaders.h b/runtime/test/d3d12_test_shaders.h index a43c141240..a6bff0e4bd 100644 --- a/runtime/test/d3d12_test_shaders.h +++ b/runtime/test/d3d12_test_shaders.h @@ -169,6 +169,19 @@ inline D3D12_RESOURCE_BARRIER transition(ID3D12Resource* resource, D3D12_RESOURC template struct Ref { T* p = nullptr; + Ref() = default; + // One owner: a copy would Release twice, and `ref = {}` must Release what it held. + Ref(const Ref&) = delete; + Ref& operator=(const Ref&) = delete; + Ref(Ref&& other) noexcept : p(other.p) { other.p = nullptr; } + Ref& operator=(Ref&& other) noexcept { + if (this != &other) { + reset(); + p = other.p; + other.p = nullptr; + } + return *this; + } ~Ref() { reset(); } void reset() { if (p) p->Release(); From 47e24615af0b9244cdad21b4b77eca4119d2f202 Mon Sep 17 00:00:00 2001 From: adrianmjim <11887815+adrianmjim@users.noreply.github.com> Date: Fri, 27 Nov 2026 21:56:21 +0100 Subject: [PATCH 2/2] test: d3d12test::Ref moves with std::exchange (TEST-REF-MOVE-ONLY) One transfer expression in both move operations, as suggested in the #1758 review. --- runtime/test/d3d12_test_shaders.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/test/d3d12_test_shaders.h b/runtime/test/d3d12_test_shaders.h index a6bff0e4bd..0e812f3f33 100644 --- a/runtime/test/d3d12_test_shaders.h +++ b/runtime/test/d3d12_test_shaders.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "../shims/d3d12_xs_rootsig.h" @@ -173,12 +174,11 @@ struct Ref { // One owner: a copy would Release twice, and `ref = {}` must Release what it held. Ref(const Ref&) = delete; Ref& operator=(const Ref&) = delete; - Ref(Ref&& other) noexcept : p(other.p) { other.p = nullptr; } + Ref(Ref&& other) noexcept : p(std::exchange(other.p, nullptr)) {} Ref& operator=(Ref&& other) noexcept { if (this != &other) { reset(); - p = other.p; - other.p = nullptr; + p = std::exchange(other.p, nullptr); } return *this; }