Skip to content

Segmentation fault on program termination with RAII Vulkan headers #138

Description

@buuugle

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    PrioritybugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions