From 6e168be8703b148e7a805832f39fb1297c293fde Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Fri, 8 Sep 2023 14:28:35 -0600 Subject: [PATCH] Make test_layer delete destroyed devices Destroyed devices need to be removed from the test_layer's created_devices vector, so that it doesn't accidentally mistake dead devices for alive ones when checking for whether a device extension is supported or not. This caused multiple days of debugging headache as it caused sporadic test failures due to the re-use of VkDevice handle values (which is caused by the memory manager reusing allocations). Since a second VkDevice could share the handle value of the first, and the first wasn't removed from the vector, test_layer would use the data assocated with the first device by mistake. --- tests/framework/layer/test_layer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/framework/layer/test_layer.cpp b/tests/framework/layer/test_layer.cpp index c2747c8b61..2764f665c1 100644 --- a/tests/framework/layer/test_layer.cpp +++ b/tests/framework/layer/test_layer.cpp @@ -654,11 +654,11 @@ VKAPI_ATTR void VKAPI_CALL test_vkDestroyDevice(VkDevice device, const VkAllocat layer.second_device_created_during_create_device.dispatch_table.DestroyDevice); } - for (auto& created_device : layer.created_devices) { - if (created_device.device_handle == device) { - created_device.dispatch_table.DestroyDevice(device, pAllocator); - break; - } + auto it = std::find_if(std::begin(layer.created_devices), std::end(layer.created_devices), + [device](const TestLayer::Device& dev) { return device == dev.device_handle; }); + if (it != std::end(layer.created_devices)) { + it->dispatch_table.DestroyDevice(device, pAllocator); + layer.created_devices.erase(it); } }