Reorder some object instantiations to get valid destruction sequence. (#1641)

This commit is contained in:
Andreas Süßenbach
2023-08-21 11:35:17 +02:00
committed by GitHub
parent d07d082af1
commit 14d048e9bf
3 changed files with 12 additions and 12 deletions

View File

@@ -67,6 +67,9 @@ int main( int /*argc*/, char ** /*argv*/ )
// See if we can use a linear tiled image for a texture, if not, we will need a staging buffer for the texture data
bool needsStaging = !( formatProperties.linearTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage );
// in order to get a clean desctruction sequence, instantiate the DeviceMemory for the image first
vk::raii::DeviceMemory imageMemory( nullptr );
vk::ImageCreateInfo imageCreateInfo( {},
vk::ImageType::e2D,
format,
@@ -89,7 +92,7 @@ int main( int /*argc*/, char ** /*argv*/ )
// allocate memory
vk::MemoryAllocateInfo memoryAllocateInfo( memoryRequirements.size, memoryTypeIndex );
vk::raii::DeviceMemory imageMemory( device, memoryAllocateInfo );
imageMemory = vk::raii::DeviceMemory( device, memoryAllocateInfo );
// bind memory
image.bindMemory( *imageMemory, 0 );
@@ -183,9 +186,6 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::ImageViewCreateInfo imageViewCreateInfo( {}, *image, vk::ImageViewType::e2D, format, {}, { vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 } );
vk::raii::ImageView imageView( device, imageViewCreateInfo );
// in order to prevent some validation layer warning, you need to explicitly free the image before the device memory
image.clear();
/* VULKAN_KEY_END */
}
catch ( vk::SystemError & err )