Index: sdl-game.cpp
===================================================================
--- sdl-game.cpp	(revision ea2b4dc7fae4c4944444ba237db611ed177ca173)
+++ sdl-game.cpp	(revision 880cfc2c386f5cc616fd4d6c165078cdf13eb20d)
@@ -152,8 +152,4 @@
    }
 
-   // Our state
-   bool show_demo_window = true;
-   bool show_another_window = false;
-
    done = false;
    while (!done) {
@@ -172,5 +168,4 @@
       }
 
-      // Resize swap chain?
       if (shouldRecreateSwapChain) {
          int width, height;
@@ -194,8 +189,4 @@
       ImGui::NewFrame();
 
-      // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
-      if (show_demo_window)
-         ImGui::ShowDemoWindow(&show_demo_window);
-
       // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
       {
@@ -205,6 +196,4 @@
 
          ImGui::Text("This is some useful text.");               // Display some text (you can use a format strings too)
-         ImGui::Checkbox("Demo Window", &show_demo_window);      // Edit bools storing our window open/close state
-         ImGui::Checkbox("Another Window", &show_another_window);
 
          if (ImGui::Button("Button"))                            // Buttons return true when clicked (most widgets return true when edited/activated)
@@ -217,15 +206,4 @@
       }
 
-      // 3. Show another simple window.
-      if (show_another_window)
-      {
-         ImGui::Begin("Another Window", &show_another_window);   // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
-         ImGui::Text("Hello from another window!");
-         if (ImGui::Button("Close Me"))
-            show_another_window = false;
-         ImGui::End();
-      }
-
-      // Rendering
       ImGui::Render();
       ImDrawData* draw_data = ImGui::GetDrawData();
@@ -329,7 +307,5 @@
    // FIXME: We could wait on the Queue if we had the queue in wd-> (otherwise VulkanH functions can't use globals)
     //vkQueueWaitIdle(g_Queue);
-   if (vkDeviceWaitIdle(device) != VK_SUCCESS) {
-      throw runtime_error("failed to wait for device!");
-   }
+   VKUTIL_CHECK_RESULT(vkDeviceWaitIdle(device), "failed to wait for device!");
 
    ImGui_ImplVulkan_Shutdown();
@@ -745,4 +721,5 @@
       poolInfo.queueFamilyIndex = indices.graphicsFamily.value();
       poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
+
       if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPools[i]) != VK_SUCCESS) {
          throw runtime_error("failed to create graphics command pool!");
@@ -787,5 +764,5 @@
 
       if (vkAllocateCommandBuffers(device, &allocInfo, &commandBuffers[i]) != VK_SUCCESS) {
-         throw runtime_error("failed to allocate command buffers!");
+         throw runtime_error("failed to allocate command buffer!");
       }
    }
@@ -823,5 +800,7 @@
       imageAcquiredSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
 
-   if (result == VK_ERROR_OUT_OF_DATE_KHR) {
+   if (result == VK_SUBOPTIMAL_KHR) {
+      shouldRecreateSwapChain = true;
+   } else if (result == VK_ERROR_OUT_OF_DATE_KHR) {
       shouldRecreateSwapChain = true;
       return;
@@ -830,5 +809,6 @@
    }
 
-   VKUTIL_CHECK_RESULT(vkWaitForFences(device, 1, &inFlightFences[imageIndex], VK_TRUE, numeric_limits<uint64_t>::max()),
+   VKUTIL_CHECK_RESULT(
+      vkWaitForFences(device, 1, &inFlightFences[imageIndex], VK_TRUE, numeric_limits<uint64_t>::max()),
       "failed waiting for fence!");
 
@@ -836,16 +816,12 @@
       "failed to reset fence!");
 
-   // START OF NEW CODE
-   // I don't have analogous code in vulkan-game right now because I record command buffers once
-   // before the render loop ever starts. I should change this
-
    VKUTIL_CHECK_RESULT(vkResetCommandPool(device, commandPools[imageIndex], 0),
       "failed to reset command pool!");
 
-   VkCommandBufferBeginInfo info = {};
-   info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
-   info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
-
-   VKUTIL_CHECK_RESULT(vkBeginCommandBuffer(commandBuffers[imageIndex], &info),
+   VkCommandBufferBeginInfo beginInfo = {};
+   beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+   beginInfo.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
+
+   VKUTIL_CHECK_RESULT(vkBeginCommandBuffer(commandBuffers[imageIndex], &beginInfo),
       "failed to begin recording command buffer!");
 
@@ -865,8 +841,6 @@
    vkCmdBeginRenderPass(commandBuffers[imageIndex], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
 
-   // Record dear imgui primitives into command buffer
    ImGui_ImplVulkan_RenderDrawData(draw_data, commandBuffers[imageIndex]);
 
-   // Submit command buffer
    vkCmdEndRenderPass(commandBuffers[imageIndex]);
 
@@ -874,8 +848,6 @@
       "failed to record command buffer!");
 
-   // END OF NEW CODE
-
    VkSemaphore waitSemaphores[] = { imageAcquiredSemaphores[currentFrame] };
-   VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
+   VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
    VkSemaphore signalSemaphores[] = { renderCompleteSemaphores[currentFrame] };
 
@@ -884,5 +856,5 @@
    submitInfo.waitSemaphoreCount = 1;
    submitInfo.pWaitSemaphores = waitSemaphores;
-   submitInfo.pWaitDstStageMask = &wait_stage;
+   submitInfo.pWaitDstStageMask = waitStages;
    submitInfo.commandBufferCount = 1;
    submitInfo.pCommandBuffers = &commandBuffers[imageIndex];
@@ -895,8 +867,4 @@
 
 void VulkanGame::presentFrame() {
-   if (shouldRecreateSwapChain) {
-      return;
-   }
-
    VkSemaphore signalSemaphores[] = { renderCompleteSemaphores[currentFrame] };
 
@@ -912,11 +880,11 @@
    VkResult result = vkQueuePresentKHR(presentQueue, &presentInfo);
 
-   // In vulkan-game, I also handle VK_SUBOPTIMAL_KHR and framebufferResized. g_SwapChainRebuild is kind of similar
-   // to framebufferResized, but not quite the same
-   if (result == VK_ERROR_OUT_OF_DATE_KHR) {
+   if (result == VK_SUBOPTIMAL_KHR) {
+      shouldRecreateSwapChain = true;
+   } else if (result == VK_ERROR_OUT_OF_DATE_KHR) {
       shouldRecreateSwapChain = true;
       return;
-   } else if (result != VK_SUCCESS) {
-      throw runtime_error("failed to present swap chain image!");
+   } else {
+      VKUTIL_CHECK_RESULT(result, "failed to present swap chain image!");
    }
 
