Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 869635a

Browse files
committed
Fix DestroyDebugReportCallbackEXT also being called when validation layers are disabled
1 parent 7fdfd50 commit 869635a

27 files changed

Lines changed: 132 additions & 27 deletions

03_Drawing_a_triangle/00_Setup/02_Validation_layers.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,10 @@ outside the class. We can then call it in the `cleanup` function:
351351
352352
```c++
353353
void cleanup() {
354-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
354+
if (enableValidationLayers) {
355+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
356+
}
357+
355358
vkDestroyInstance(instance, nullptr);
356359
357360
glfwDestroyWindow(window);

code/02_validation_layers.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ class HelloTriangleApplication {
7272
}
7373

7474
void cleanup() {
75-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
75+
if (enableValidationLayers) {
76+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
77+
}
78+
7679
vkDestroyInstance(instance, nullptr);
7780

7881
glfwDestroyWindow(window);

code/03_physical_device_selection.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ class HelloTriangleApplication {
8383
}
8484

8585
void cleanup() {
86-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
86+
if (enableValidationLayers) {
87+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
88+
}
89+
8790
vkDestroyInstance(instance, nullptr);
8891

8992
glfwDestroyWindow(window);

code/04_logical_device.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ class HelloTriangleApplication {
8888

8989
void cleanup() {
9090
vkDestroyDevice(device, nullptr);
91-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
91+
92+
if (enableValidationLayers) {
93+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
94+
}
95+
9296
vkDestroyInstance(instance, nullptr);
9397

9498
glfwDestroyWindow(window);

code/05_window_surface.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ class HelloTriangleApplication {
9393

9494
void cleanup() {
9595
vkDestroyDevice(device, nullptr);
96-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
96+
97+
if (enableValidationLayers) {
98+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
99+
}
100+
97101
vkDestroySurfaceKHR(instance, surface, nullptr);
98102
vkDestroyInstance(instance, nullptr);
99103

code/06_swap_chain_creation.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ class HelloTriangleApplication {
111111
void cleanup() {
112112
vkDestroySwapchainKHR(device, swapChain, nullptr);
113113
vkDestroyDevice(device, nullptr);
114-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
114+
115+
if (enableValidationLayers) {
116+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
117+
}
118+
115119
vkDestroySurfaceKHR(instance, surface, nullptr);
116120
vkDestroyInstance(instance, nullptr);
117121

code/07_image_views.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ class HelloTriangleApplication {
117117

118118
vkDestroySwapchainKHR(device, swapChain, nullptr);
119119
vkDestroyDevice(device, nullptr);
120-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
120+
121+
if (enableValidationLayers) {
122+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
123+
}
124+
121125
vkDestroySurfaceKHR(instance, surface, nullptr);
122126
vkDestroyInstance(instance, nullptr);
123127

code/08_graphics_pipeline.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ class HelloTriangleApplication {
118118

119119
vkDestroySwapchainKHR(device, swapChain, nullptr);
120120
vkDestroyDevice(device, nullptr);
121-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
121+
122+
if (enableValidationLayers) {
123+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
124+
}
125+
122126
vkDestroySurfaceKHR(instance, surface, nullptr);
123127
vkDestroyInstance(instance, nullptr);
124128

code/09_shader_modules.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ class HelloTriangleApplication {
119119

120120
vkDestroySwapchainKHR(device, swapChain, nullptr);
121121
vkDestroyDevice(device, nullptr);
122-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
122+
123+
if (enableValidationLayers) {
124+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
125+
}
126+
123127
vkDestroySurfaceKHR(instance, surface, nullptr);
124128
vkDestroyInstance(instance, nullptr);
125129

code/10_fixed_functions.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ class HelloTriangleApplication {
123123

124124
vkDestroySwapchainKHR(device, swapChain, nullptr);
125125
vkDestroyDevice(device, nullptr);
126-
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
126+
127+
if (enableValidationLayers) {
128+
DestroyDebugReportCallbackEXT(instance, callback, nullptr);
129+
}
130+
127131
vkDestroySurfaceKHR(instance, surface, nullptr);
128132
vkDestroyInstance(instance, nullptr);
129133

0 commit comments

Comments
 (0)