Skip to content

Commit 6cf840a

Browse files
committed
Fix waitForFences usage
Properly check return value and throw on error Fix Rendering and presentation chapter paragraph Adjust documentation for multi threading chapter to actuall match code
1 parent 1b2dfc4 commit 6cf840a

27 files changed

+152
-61
lines changed

attachments/15_hello_triangle.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,11 @@ class HelloTriangleApplication
467467
vk::PipelineStageFlags waitDestinationStageMask(vk::PipelineStageFlagBits::eColorAttachmentOutput);
468468
const vk::SubmitInfo submitInfo{.waitSemaphoreCount = 1, .pWaitSemaphores = &*presentCompleteSemaphore, .pWaitDstStageMask = &waitDestinationStageMask, .commandBufferCount = 1, .pCommandBuffers = &*commandBuffer, .signalSemaphoreCount = 1, .pSignalSemaphores = &*renderFinishedSemaphore};
469469
queue.submit(submitInfo, *drawFence);
470-
while (vk::Result::eTimeout == device.waitForFences(*drawFence, vk::True, UINT64_MAX))
471-
;
470+
result = device.waitForFences(*drawFence, vk::True, UINT64_MAX);
471+
if (result != vk::Result::eSuccess)
472+
{
473+
throw std::runtime_error("failed to wait for fence!");
474+
}
472475

473476
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1, .pWaitSemaphores = &*renderFinishedSemaphore, .swapchainCount = 1, .pSwapchains = &*swapChain, .pImageIndices = &imageIndex};
474477
result = queue.presentKHR(presentInfoKHR);

attachments/16_frames_in_flight.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,11 @@ class HelloTriangleApplication
471471
{
472472
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
473473
// while renderFinishedSemaphores is indexed by imageIndex
474-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
475-
;
474+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
475+
if (fenceResult != vk::Result::eSuccess)
476+
{
477+
throw std::runtime_error("failed to wait for fence!");
478+
}
476479
device.resetFences(*inFlightFences[frameIndex]);
477480

478481
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

attachments/17_swap_chain_recreation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,11 @@ class HelloTriangleApplication
505505
{
506506
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
507507
// while renderFinishedSemaphores is indexed by imageIndex
508-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
509-
;
508+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
509+
if (fenceResult != vk::Result::eSuccess)
510+
{
511+
throw std::runtime_error("failed to wait for fence!");
512+
}
510513
device.resetFences(*inFlightFences[frameIndex]);
511514

512515
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

attachments/18_vertex_input.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,11 @@ class HelloTriangleApplication
524524
{
525525
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
526526
// while renderFinishedSemaphores is indexed by imageIndex
527-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
528-
;
527+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
528+
if (fenceResult != vk::Result::eSuccess)
529+
{
530+
throw std::runtime_error("failed to wait for fence!");
531+
}
529532
device.resetFences(*inFlightFences[frameIndex]);
530533

531534
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

attachments/19_vertex_buffer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,11 @@ class HelloTriangleApplication
560560
{
561561
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
562562
// while renderFinishedSemaphores is indexed by imageIndex
563-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
564-
;
563+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
564+
if (fenceResult != vk::Result::eSuccess)
565+
{
566+
throw std::runtime_error("failed to wait for fence!");
567+
}
565568
device.resetFences(*inFlightFences[frameIndex]);
566569

567570
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

attachments/20_staging_buffer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,11 @@ class HelloTriangleApplication
580580
{
581581
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
582582
// while renderFinishedSemaphores is indexed by imageIndex
583-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
584-
;
583+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
584+
if (fenceResult != vk::Result::eSuccess)
585+
{
586+
throw std::runtime_error("failed to wait for fence!");
587+
}
585588
device.resetFences(*inFlightFences[frameIndex]);
586589

587590
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

attachments/21_index_buffer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,11 @@ class HelloTriangleApplication
606606
{
607607
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
608608
// while renderFinishedSemaphores is indexed by imageIndex
609-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
610-
;
609+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
610+
if (fenceResult != vk::Result::eSuccess)
611+
{
612+
throw std::runtime_error("failed to wait for fence!");
613+
}
611614
device.resetFences(*inFlightFences[frameIndex]);
612615

613616
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

attachments/22_descriptor_layout.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,11 @@ class HelloTriangleApplication
665665
{
666666
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
667667
// while renderFinishedSemaphores is indexed by imageIndex
668-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
669-
;
668+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
669+
if (fenceResult != vk::Result::eSuccess)
670+
{
671+
throw std::runtime_error("failed to wait for fence!");
672+
}
670673
device.resetFences(*inFlightFences[frameIndex]);
671674

672675
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

attachments/23_descriptor_sets.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,11 @@ class HelloTriangleApplication
693693
{
694694
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
695695
// while renderFinishedSemaphores is indexed by imageIndex
696-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
697-
;
696+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
697+
if (fenceResult != vk::Result::eSuccess)
698+
{
699+
throw std::runtime_error("failed to wait for fence!");
700+
}
698701
device.resetFences(*inFlightFences[frameIndex]);
699702

700703
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

attachments/24_texture_image.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,11 @@ class HelloTriangleApplication
802802
{
803803
// Note: inFlightFences, presentCompleteSemaphores, and commandBuffers are indexed by frameIndex,
804804
// while renderFinishedSemaphores is indexed by imageIndex
805-
while (vk::Result::eTimeout == device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX))
806-
;
805+
auto fenceResult = device.waitForFences(*inFlightFences[frameIndex], vk::True, UINT64_MAX);
806+
if (fenceResult != vk::Result::eSuccess)
807+
{
808+
throw std::runtime_error("failed to wait for fence!");
809+
}
807810
device.resetFences(*inFlightFences[frameIndex]);
808811

809812
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);

0 commit comments

Comments
 (0)