diff --git a/src/gfxstream/guest/vulkan/gfxstream_vk_cmd.cpp b/src/gfxstream/guest/vulkan/gfxstream_vk_cmd.cpp index 2039e082d1e..ac617e10047 100644 --- a/src/gfxstream/guest/vulkan/gfxstream_vk_cmd.cpp +++ b/src/gfxstream/guest/vulkan/gfxstream_vk_cmd.cpp @@ -171,20 +171,26 @@ void gfxstream_vk_FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, VK_FROM_HANDLE(gfxstream_vk_command_pool, gfxstream_commandPool, commandPool); { // Set up internal commandBuffer array for gfxstream-internal call - std::vector internal_objects(commandBufferCount); + std::vector internal_objects; + internal_objects.reserve(commandBufferCount); for (uint32_t i = 0; i < commandBufferCount; i++) { VK_FROM_HANDLE(gfxstream_vk_command_buffer, gfxstream_commandBuffer, pCommandBuffers[i]); - internal_objects[i] = gfxstream_commandBuffer->internal_object; + if (gfxstream_commandBuffer) { + internal_objects.push_back(gfxstream_commandBuffer->internal_object); + } } auto vkEnc = gfxstream::vk::ResourceTracker::getThreadLocalEncoder(); vkEnc->vkFreeCommandBuffers(gfxstream_device->internal_object, - gfxstream_commandPool->internal_object, commandBufferCount, + gfxstream_commandPool->internal_object, + internal_objects.size(), internal_objects.data(), true /* do lock */); } for (uint32_t i = 0; i < commandBufferCount; i++) { VK_FROM_HANDLE(gfxstream_vk_command_buffer, gfxstream_commandBuffer, pCommandBuffers[i]); - vk_command_buffer_destroyOp(&gfxstream_commandBuffer->vk); + if (gfxstream_commandBuffer) { + vk_command_buffer_destroyOp(&gfxstream_commandBuffer->vk); + } } }