Segmentation fault on program termination with RAII Vulkan headers

Open
#138 12 comments 2 reactions 0 assignees View on GitHub

@ozanyasindogan is already working on this.

Since Aug 8, 2026.

  • #443 by @ozanyasindogan — open
  • #453 by @SaschaWillems — closed without merging

Assessment

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

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.

Description

bug Priority

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?

Dominant language
C++
Stars
424
Forks
127
Avg merge
2d 22h
Merged PRs (30d)
7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from KhronosGroup/Vulkan-Tutorial

All issues in KhronosGroup/Vulkan-Tutorial

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.