Skip to content

Commit 801087e

Browse files
committed
Check some samples to ensure device is defined - avoid crash on exit
1 parent 87a4e8f commit 801087e

4 files changed

Lines changed: 23 additions & 11 deletions

File tree

samples/api/texture_loading/texture_loading.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019-2025, Sascha Willems
1+
/* Copyright (c) 2019-2026, Sascha Willems
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -408,10 +408,13 @@ void TextureLoading::load_texture()
408408
// Free all Vulkan resources used by a texture object
409409
void TextureLoading::destroy_texture(Texture texture)
410410
{
411-
vkDestroyImageView(get_device().get_handle(), texture.view, nullptr);
412-
vkDestroyImage(get_device().get_handle(), texture.image, nullptr);
413-
vkDestroySampler(get_device().get_handle(), texture.sampler, nullptr);
414-
vkFreeMemory(get_device().get_handle(), texture.device_memory, nullptr);
411+
if (has_device())
412+
{
413+
vkDestroyImageView(get_device().get_handle(), texture.view, nullptr);
414+
vkDestroyImage(get_device().get_handle(), texture.image, nullptr);
415+
vkDestroySampler(get_device().get_handle(), texture.sampler, nullptr);
416+
vkFreeMemory(get_device().get_handle(), texture.device_memory, nullptr);
417+
}
415418
}
416419

417420
void TextureLoading::build_command_buffers()

samples/api/texture_mipmap_generation/texture_mipmap_generation.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019-2025, Sascha Willems
1+
/* Copyright (c) 2019-2026, Sascha Willems
22
*
33
* SPDX-License-Identifier: Apache-2.0
44
*
@@ -285,9 +285,12 @@ void TextureMipMapGeneration::load_texture_generate_mipmaps(std::string file_nam
285285
// Free all Vulkan resources used by a texture object
286286
void TextureMipMapGeneration::destroy_texture(Texture texture)
287287
{
288-
vkDestroyImageView(get_device().get_handle(), texture.view, nullptr);
289-
vkDestroyImage(get_device().get_handle(), texture.image, nullptr);
290-
vkFreeMemory(get_device().get_handle(), texture.device_memory, nullptr);
288+
if (has_device())
289+
{
290+
vkDestroyImageView(get_device().get_handle(), texture.view, nullptr);
291+
vkDestroyImage(get_device().get_handle(), texture.image, nullptr);
292+
vkFreeMemory(get_device().get_handle(), texture.device_memory, nullptr);
293+
}
291294
}
292295

293296
void TextureMipMapGeneration::load_assets()

samples/performance/hpp_pipeline_cache/hpp_pipeline_cache.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ HPPPipelineCache::~HPPPipelineCache()
4040
get_device().get_handle().destroyPipelineCache(pipeline_cache);
4141
}
4242

43-
vkb::fs::write_temp(get_device().get_resource_cache().serialize(), "hpp_cache.data");
43+
if (has_device())
44+
{
45+
vkb::fs::write_temp(get_device().get_resource_cache().serialize(), "hpp_cache.data");
46+
}
4447
}
4548

4649
bool HPPPipelineCache::prepare(const vkb::ApplicationOptions &options)

samples/performance/pipeline_cache/pipeline_cache.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ PipelineCache::~PipelineCache()
7070
vkDestroyPipelineCache(get_device().get_handle(), pipeline_cache, nullptr);
7171
}
7272

73-
vkb::fs::write_temp(get_device().get_resource_cache().serialize(), "cache.data");
73+
if (has_device())
74+
{
75+
vkb::fs::write_temp(get_device().get_resource_cache().serialize(), "cache.data");
76+
}
7477
}
7578

7679
bool PipelineCache::prepare(const vkb::ApplicationOptions &options)

0 commit comments

Comments
 (0)