From d4ddb0a2cd4a5257884b40b6efa54d05a8e2bd27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Mon, 8 Apr 2019 11:33:49 +0200 Subject: [PATCH] Add error check before filling a vector of UniqueHandles from just created handles. (#319) --- VulkanHppGenerator.cpp | 10 ++-- vulkan/vulkan.hpp | 120 ++++++++++++++++++++++++----------------- 2 files changed, 78 insertions(+), 52 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index cf09ca6..782c901 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -2899,11 +2899,13 @@ ${i} std::vector, Allocator> ${typeVariable}s${ ${i} ${typeVariable}s.reserve( ${vectorSize} ); ${i} ${type}* buffer = reinterpret_cast<${type}*>( reinterpret_cast( ${typeVariable}s.data() ) + ${vectorSize} * ( sizeof( UniqueHandle<${type}, Dispatch> ) - sizeof( ${type} ) ) ); ${i} Result result = static_cast(d.vk${command}( m_device, ${arguments}, reinterpret_cast( buffer ) ) ); - -${i} ${Deleter}<${DeleterTemplate},Dispatch> deleter( *this, ${deleterArg}, d ); -${i} for ( size_t i=0 ; i<${vectorSize} ; i++ ) +${i} if (result == vk::Result::eSuccess) ${i} { -${i} ${typeVariable}s.push_back( UniqueHandle<${type}, Dispatch>( buffer[i], deleter ) ); +${i} ${Deleter}<${DeleterTemplate},Dispatch> deleter( *this, ${deleterArg}, d ); +${i} for ( size_t i=0 ; i<${vectorSize} ; i++ ) +${i} { +${i} ${typeVariable}s.push_back( UniqueHandle<${type}, Dispatch>( buffer[i], deleter ) ); +${i} } ${i} } ${i} return createResultValue( result, ${typeVariable}s, VULKAN_HPP_NAMESPACE_STRING "::${class}::${commandName}Unique" ); diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index a19cc9f..ada8bbe 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -48675,11 +48675,13 @@ namespace VULKAN_HPP_NAMESPACE commandBuffers.reserve( allocateInfo.commandBufferCount ); CommandBuffer* buffer = reinterpret_cast( reinterpret_cast( commandBuffers.data() ) + allocateInfo.commandBufferCount * ( sizeof( UniqueHandle ) - sizeof( CommandBuffer ) ) ); Result result = static_cast(d.vkAllocateCommandBuffers( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( buffer ) ) ); - - PoolFree deleter( *this, allocateInfo.commandPool, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + PoolFree deleter( *this, allocateInfo.commandPool, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, commandBuffers, VULKAN_HPP_NAMESPACE_STRING "::Device::allocateCommandBuffersUnique" ); @@ -48692,11 +48694,13 @@ namespace VULKAN_HPP_NAMESPACE commandBuffers.reserve( allocateInfo.commandBufferCount ); CommandBuffer* buffer = reinterpret_cast( reinterpret_cast( commandBuffers.data() ) + allocateInfo.commandBufferCount * ( sizeof( UniqueHandle ) - sizeof( CommandBuffer ) ) ); Result result = static_cast(d.vkAllocateCommandBuffers( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( buffer ) ) ); - - PoolFree deleter( *this, allocateInfo.commandPool, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + PoolFree deleter( *this, allocateInfo.commandPool, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, commandBuffers, VULKAN_HPP_NAMESPACE_STRING "::Device::allocateCommandBuffersUnique" ); @@ -48733,11 +48737,13 @@ namespace VULKAN_HPP_NAMESPACE descriptorSets.reserve( allocateInfo.descriptorSetCount ); DescriptorSet* buffer = reinterpret_cast( reinterpret_cast( descriptorSets.data() ) + allocateInfo.descriptorSetCount * ( sizeof( UniqueHandle ) - sizeof( DescriptorSet ) ) ); Result result = static_cast(d.vkAllocateDescriptorSets( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( buffer ) ) ); - - PoolFree deleter( *this, allocateInfo.descriptorPool, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + PoolFree deleter( *this, allocateInfo.descriptorPool, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, descriptorSets, VULKAN_HPP_NAMESPACE_STRING "::Device::allocateDescriptorSetsUnique" ); @@ -48750,11 +48756,13 @@ namespace VULKAN_HPP_NAMESPACE descriptorSets.reserve( allocateInfo.descriptorSetCount ); DescriptorSet* buffer = reinterpret_cast( reinterpret_cast( descriptorSets.data() ) + allocateInfo.descriptorSetCount * ( sizeof( UniqueHandle ) - sizeof( DescriptorSet ) ) ); Result result = static_cast(d.vkAllocateDescriptorSets( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( buffer ) ) ); - - PoolFree deleter( *this, allocateInfo.descriptorPool, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + PoolFree deleter( *this, allocateInfo.descriptorPool, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, descriptorSets, VULKAN_HPP_NAMESPACE_STRING "::Device::allocateDescriptorSetsUnique" ); @@ -49043,11 +49051,13 @@ namespace VULKAN_HPP_NAMESPACE pipelines.reserve( createInfos.size() ); Pipeline* buffer = reinterpret_cast( reinterpret_cast( pipelines.data() ) + createInfos.size() * ( sizeof( UniqueHandle ) - sizeof( Pipeline ) ) ); Result result = static_cast(d.vkCreateComputePipelines( m_device, static_cast( pipelineCache ), createInfos.size() , reinterpret_cast( createInfos.data() ), reinterpret_cast( static_cast( allocator ) ), reinterpret_cast( buffer ) ) ); - - ObjectDestroy deleter( *this, allocator, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + ObjectDestroy deleter( *this, allocator, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, pipelines, VULKAN_HPP_NAMESPACE_STRING "::Device::createComputePipelinesUnique" ); @@ -49060,11 +49070,13 @@ namespace VULKAN_HPP_NAMESPACE pipelines.reserve( createInfos.size() ); Pipeline* buffer = reinterpret_cast( reinterpret_cast( pipelines.data() ) + createInfos.size() * ( sizeof( UniqueHandle ) - sizeof( Pipeline ) ) ); Result result = static_cast(d.vkCreateComputePipelines( m_device, static_cast( pipelineCache ), createInfos.size() , reinterpret_cast( createInfos.data() ), reinterpret_cast( static_cast( allocator ) ), reinterpret_cast( buffer ) ) ); - - ObjectDestroy deleter( *this, allocator, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + ObjectDestroy deleter( *this, allocator, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, pipelines, VULKAN_HPP_NAMESPACE_STRING "::Device::createComputePipelinesUnique" ); @@ -49299,11 +49311,13 @@ namespace VULKAN_HPP_NAMESPACE pipelines.reserve( createInfos.size() ); Pipeline* buffer = reinterpret_cast( reinterpret_cast( pipelines.data() ) + createInfos.size() * ( sizeof( UniqueHandle ) - sizeof( Pipeline ) ) ); Result result = static_cast(d.vkCreateGraphicsPipelines( m_device, static_cast( pipelineCache ), createInfos.size() , reinterpret_cast( createInfos.data() ), reinterpret_cast( static_cast( allocator ) ), reinterpret_cast( buffer ) ) ); - - ObjectDestroy deleter( *this, allocator, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + ObjectDestroy deleter( *this, allocator, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, pipelines, VULKAN_HPP_NAMESPACE_STRING "::Device::createGraphicsPipelinesUnique" ); @@ -49316,11 +49330,13 @@ namespace VULKAN_HPP_NAMESPACE pipelines.reserve( createInfos.size() ); Pipeline* buffer = reinterpret_cast( reinterpret_cast( pipelines.data() ) + createInfos.size() * ( sizeof( UniqueHandle ) - sizeof( Pipeline ) ) ); Result result = static_cast(d.vkCreateGraphicsPipelines( m_device, static_cast( pipelineCache ), createInfos.size() , reinterpret_cast( createInfos.data() ), reinterpret_cast( static_cast( allocator ) ), reinterpret_cast( buffer ) ) ); - - ObjectDestroy deleter( *this, allocator, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + ObjectDestroy deleter( *this, allocator, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, pipelines, VULKAN_HPP_NAMESPACE_STRING "::Device::createGraphicsPipelinesUnique" ); @@ -49555,11 +49571,13 @@ namespace VULKAN_HPP_NAMESPACE pipelines.reserve( createInfos.size() ); Pipeline* buffer = reinterpret_cast( reinterpret_cast( pipelines.data() ) + createInfos.size() * ( sizeof( UniqueHandle ) - sizeof( Pipeline ) ) ); Result result = static_cast(d.vkCreateRayTracingPipelinesNV( m_device, static_cast( pipelineCache ), createInfos.size() , reinterpret_cast( createInfos.data() ), reinterpret_cast( static_cast( allocator ) ), reinterpret_cast( buffer ) ) ); - - ObjectDestroy deleter( *this, allocator, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + ObjectDestroy deleter( *this, allocator, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, pipelines, VULKAN_HPP_NAMESPACE_STRING "::Device::createRayTracingPipelinesNVUnique" ); @@ -49572,11 +49590,13 @@ namespace VULKAN_HPP_NAMESPACE pipelines.reserve( createInfos.size() ); Pipeline* buffer = reinterpret_cast( reinterpret_cast( pipelines.data() ) + createInfos.size() * ( sizeof( UniqueHandle ) - sizeof( Pipeline ) ) ); Result result = static_cast(d.vkCreateRayTracingPipelinesNV( m_device, static_cast( pipelineCache ), createInfos.size() , reinterpret_cast( createInfos.data() ), reinterpret_cast( static_cast( allocator ) ), reinterpret_cast( buffer ) ) ); - - ObjectDestroy deleter( *this, allocator, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + ObjectDestroy deleter( *this, allocator, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, pipelines, VULKAN_HPP_NAMESPACE_STRING "::Device::createRayTracingPipelinesNVUnique" ); @@ -49811,11 +49831,13 @@ namespace VULKAN_HPP_NAMESPACE swapchainKHRs.reserve( createInfos.size() ); SwapchainKHR* buffer = reinterpret_cast( reinterpret_cast( swapchainKHRs.data() ) + createInfos.size() * ( sizeof( UniqueHandle ) - sizeof( SwapchainKHR ) ) ); Result result = static_cast(d.vkCreateSharedSwapchainsKHR( m_device, createInfos.size() , reinterpret_cast( createInfos.data() ), reinterpret_cast( static_cast( allocator ) ), reinterpret_cast( buffer ) ) ); - - ObjectDestroy deleter( *this, allocator, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + ObjectDestroy deleter( *this, allocator, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, swapchainKHRs, VULKAN_HPP_NAMESPACE_STRING "::Device::createSharedSwapchainsKHRUnique" ); @@ -49828,11 +49850,13 @@ namespace VULKAN_HPP_NAMESPACE swapchainKHRs.reserve( createInfos.size() ); SwapchainKHR* buffer = reinterpret_cast( reinterpret_cast( swapchainKHRs.data() ) + createInfos.size() * ( sizeof( UniqueHandle ) - sizeof( SwapchainKHR ) ) ); Result result = static_cast(d.vkCreateSharedSwapchainsKHR( m_device, createInfos.size() , reinterpret_cast( createInfos.data() ), reinterpret_cast( static_cast( allocator ) ), reinterpret_cast( buffer ) ) ); - - ObjectDestroy deleter( *this, allocator, d ); - for ( size_t i=0 ; i( buffer[i], deleter ) ); + ObjectDestroy deleter( *this, allocator, d ); + for ( size_t i=0 ; i( buffer[i], deleter ) ); + } } return createResultValue( result, swapchainKHRs, VULKAN_HPP_NAMESPACE_STRING "::Device::createSharedSwapchainsKHRUnique" );