KhronosGroup / KhronosGroup/Vulkan-Tutorial

Segmentation fault on program termination with RAII Vulkan headers

Open
#138 12 comments 2 reactions 0 assignees Claimed by @ozanyasindogan View on GitHub
bug Priority
Dominant language
C++
Stars
418
Forks
126
Avg merge
11d 6h
Merged PRs (30d)
31

Description

Hi!
I followed the new tutorial that uses RAII Vulkan headers. Everything works fine, but there is one problem: before the program terminates, when the HelloTriangleApplication instance is destroyed, all the vk::raii objects are destroyed after the `glfwDestroyWindow` and `glfwTerminate` calls, which creates a segmentation fault. To avoid this, I added this code to the `cleanup` function:
```
void cleanup() {
inFlightFences.clear();
renderSemaphores.clear();
presentSemaphores.clear();
commandBuffers.clear();
commandPool = nullptr;
pipeline = nullptr;
pipelineLayout = nullptr;
imageViews.clear();
images.clear();
swapChain = nullptr;
surface = nullptr;
queue = nullptr;
device = nullptr;
physicalDevice = nullptr;
debugMessenger = nullptr;
instance = nullptr;

glfwDestroyWindow(window);
window = nullptr;
glfwTerminate();
}
```
This allows all destructors of Vulkan objects to be called before the GLFW window is destroyed.
I find this solution inconvenient because it completely kills the benefits of RAII.

Am I missing something in the tutorial?

Contributor guide

Open the contributing guide

Research direction

Start with the tutorial's RAII Vulkan example and inspect the HelloTriangleApplication cleanup function and destruction order around glfwDestroyWindow and glfwTerminate. Compare the open pull request linked to this issue before making changes. Done means the tutorial no longer segfaults during termination while retaining the RAII object lifetime behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.