#Crash when trying to render Imgui

3 messages · Page 1 of 1 (latest)

wanton perch
#

Trying to add Imgui to my project. This is the render loop:

while (!glfwWindowShouldClose(window))
{
    double currentTime = glfwGetTime();
    double deltaTime = currentTime - lastTime;
    lastTime = currentTime;
    glfwPollEvents();
    int width, height;
    glfwGetWindowSize(window, &width, &height);

    game.update();

    if (width > 0 && height > 0)
    {
        processInput(window, game.camera, deltaTime);
        draw(queue_family_indices,game.camera,queue_family_indices,width,height);

        if (currentTime-delay>=1)
        {
            spdlog::info("FPS: {}", 1.0 / deltaTime);
            delay = currentTime;
            glm::ivec3 camPos =Game::calculateChunkPosition(game.camera.position);
            spdlog::info("Camera position: {},{}, {}", camPos.x, camPos.y, camPos.z);
        }

    }
    if (glfwGetWindowAttrib(window,GLFW_ICONIFIED)!=0)
    {
        ImGui_ImplGlfw_Sleep(10);
    }
    vkDeviceWaitIdle(device);
}

This is draw - https://pastebin.com/B8mtP1Ht
This is recordCommandBuffer - https://pastebin.com/V7ekrx2w

It crashes on ImGui_ImplVulkan_RenderDrawData with code -1000069000

narrow stone
#

From what I can tell is that you are drawing ImGui before you begin your command buffer

VkCommandBufferBeginInfo begin_info{};
        begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
 
        ImGui_ImplVulkan_NewFrame();
        ImGui_ImplGlfw_NewFrame();
        ImGui::NewFrame();
        ImGui::ShowDemoWindow();
        ImGui::Render();
 
        if (vkBeginCommandBuffer(command_buffer, &begin_info))
            throw std::runtime_error("Failed to begin recording command buffer");

Try this instead

VkCommandBufferBeginInfo begin_info{};
        begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
 
        if (vkBeginCommandBuffer(command_buffer, &begin_info))
            throw std::runtime_error("Failed to begin recording command buffer");

        ImGui_ImplVulkan_NewFrame();
        ImGui_ImplGlfw_NewFrame();
        ImGui::NewFrame();
        ImGui::ShowDemoWindow();
        ImGui::Render();
wanton perch
#

Nevermind, I needed to increase the descriptor count