engineer1109 / LearnVulkan

Learn Vulkan. Advanced examples of Vulkan, QT, CUDA, OpenCV for Linux, Windows, Android.
GNU General Public License v3.0
136 stars 22 forks source link

crash when use QtVulkan #3

Open 173619070 opened 1 year ago

173619070 commented 1 year ago

crash code: (file :VulkanBase.cxx, project:QtVulkanSceneDemo)

void VulkanBase::draw() {
    if (m_stop or m_pause) return;
    m_signalFrame = false;
    prepareFrame();

    // Command buffer to be sumitted to the queue
    m_submitInfo.commandBufferCount = 1;
    m_submitInfo.pCommandBuffers = &m_drawCmdBuffers[m_currentBuffer];

    // Submit to queue
    if (m_prepared) {
        VK_CHECK_RESULT(vkQueueSubmit(m_queue, 1, &m_submitInfo, VK_NULL_HANDLE));/////<-------crash
    }

    submitFrame();
    m_signalFrame = true;
}
173619070 commented 1 year ago

fixed reacquire next image after call windowResize


void VulkanBase::prepareFrame() {
    if (m_pause or !m_prepared) {
        return;
    }
    // Acquire the next image from the swap chain
    VkResult err = m_swapChain.acquireNextImage(m_semaphores.presentComplete, &m_currentBuffer);
    // Recreate the swapchain if it's no longer compatible with the surface (OUT_OF_DATE) or no longer optimal for presentation (SUBOPTIMAL)
    if ((err == VK_ERROR_OUT_OF_DATE_KHR) || (err == VK_SUBOPTIMAL_KHR)) {
        LOGI("VulkanEngine VK_ERROR_OUT_OF_DATE_KHR");
        windowResize();
        //////////////-----reacquire next image
        VkResult err = m_swapChain.acquireNextImage(m_semaphores.presentComplete, &m_currentBuffer);
        if ((err == VK_ERROR_OUT_OF_DATE_KHR) || (err == VK_SUBOPTIMAL_KHR)) {
            LOGI("VulkanEngine VK_ERROR_OUT_OF_DATE_KHR");

        }
    } else {
        VK_CHECK_RESULT(err);
    }
    VK_CHECK_RESULT(vkQueueWaitIdle(m_queue));
}
engineer1109 commented 1 year ago

@173619070 Are you on Intel?

173619070 commented 1 year ago

@173619070 Are you on Intel? yes, Intel UHD Graphics 620,i used the Intel graphics card before. then I tried to replace it with an independent graphics card(NVIDIA MX150). and there was no crash now,thanks a lot! but i think it is more efficient to use the vkWaitForFences instead of vkQueueWaitIdle when submit or present, what do you think.

engineer1109 commented 1 year ago

@173619070 https://github.com/engineer1109/LearnVulkan/commit/210c9dc0ba290243f91f8c21d03243ff60d3243b should fix intel crash. Wait for fence suggestion I need time to check.