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

Skip to content

Commit be8923d

Browse files
committed
Fix debug messenger being stored in confusingly named callback variable
1 parent 077b734 commit be8923d

29 files changed

Lines changed: 297 additions & 297 deletions

03_Drawing_a_triangle/00_Setup/02_Validation_layers.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ If the check was successful then `vkCreateInstance` should not ever return a
169169

170170
Unfortunately just enabling the layers doesn't help much, because they currently
171171
have no way to relay the debug messages back to our program. To receive those
172-
messages we have to set up a callback, which requires the `VK_EXT_debug_utils`
172+
messages we have to set up a debug messenger with a callback, which requires the `VK_EXT_debug_utils`
173173
extension.
174174

175175
We'll first create a `getRequiredExtensions` function that will return the
@@ -192,7 +192,7 @@ std::vector<const char*> getRequiredExtensions() {
192192
}
193193
```
194194

195-
The extensions specified by GLFW are always required, but the debug report
195+
The extensions specified by GLFW are always required, but the debug messenger
196196
extension is conditionally added. Note that I've used the
197197
`VK_EXT_DEBUG_UTILS_EXTENSION_NAME` macro here which is equal to the literal
198198
string "VK_EXT_debug_utils". Using this macro lets you avoid typos.
@@ -210,7 +210,7 @@ Run the program to make sure you don't receive a
210210
existence of this extension, because it should be implied by the availability of
211211
the validation layers.
212212

213-
Now let's see what a callback function looks like. Add a new static member
213+
Now let's see what a debug callback function looks like. Add a new static member
214214
function called `debugCallback` with the `PFN_vkDebugUtilsMessengerCallbackEXT`
215215
prototype. The `VKAPI_ATTR` and `VKAPI_CALL` ensure that the function has the
216216
right signature for Vulkan to call it.
@@ -265,29 +265,29 @@ always return `VK_FALSE`.
265265

266266
All that remains now is telling Vulkan about the callback function. Perhaps
267267
somewhat surprisingly, even the debug callback in Vulkan is managed with a
268-
handle that needs to be explicitly created and destroyed. Such a callback is called a *messenger* and you can have as many of them as you want. Add a class member for
268+
handle that needs to be explicitly created and destroyed. Such a callback is part of a *debug messenger* and you can have as many of them as you want. Add a class member for
269269
this handle right under `instance`:
270270

271271
```c++
272-
VkDebugUtilsMessengerEXT callback;
272+
VkDebugUtilsMessengerEXT debugMessenger;
273273
```
274274

275-
Now add a function `setupDebugCallback` to be called from `initVulkan` right
275+
Now add a function `setupDebugMessenger` to be called from `initVulkan` right
276276
after `createInstance`:
277277

278278
```c++
279279
void initVulkan() {
280280
createInstance();
281-
setupDebugCallback();
281+
setupDebugMessenger();
282282
}
283283

284-
void setupDebugCallback() {
284+
void setupDebugMessenger() {
285285
if (!enableValidationLayers) return;
286286

287287
}
288288
```
289289

290-
We'll need to fill in a structure with details about the callback:
290+
We'll need to fill in a structure with details about the messenger and its callback:
291291

292292
```c++
293293
VkDebugUtilsMessengerCreateInfoEXT createInfo = {};
@@ -314,10 +314,10 @@ create our own proxy function that handles this in the background. I've added it
314314
right above the `HelloTriangleApplication` class definition.
315315

316316
```c++
317-
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pCallback) {
317+
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) {
318318
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
319319
if (func != nullptr) {
320-
return func(instance, pCreateInfo, pAllocator, pCallback);
320+
return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
321321
} else {
322322
return VK_ERROR_EXTENSION_NOT_PRESENT;
323323
}
@@ -329,14 +329,14 @@ couldn't be loaded. We can now call this function to create the extension
329329
object if it's available:
330330
331331
```c++
332-
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &callback) != VK_SUCCESS) {
333-
throw std::runtime_error("failed to set up debug callback!");
332+
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger) != VK_SUCCESS) {
333+
throw std::runtime_error("failed to set up debug messenger!");
334334
}
335335
```
336336

337337
The second to last parameter is again the optional allocator callback that we
338338
set to `nullptr`, other than that the parameters are fairly straightforward.
339-
Since the debug callback is specific to our Vulkan instance and its layers, it
339+
Since the debug messenger is specific to our Vulkan instance and its layers, it
340340
needs to be explicitly specified as first argument. You will also see this
341341
pattern with other *child* objects later on. Let's see if it works... Run the
342342
program and close the window once you're fed up with staring at the blank
@@ -353,10 +353,10 @@ Create another proxy function right
353353
below `CreateDebugUtilsMessengerEXT`:
354354

355355
```c++
356-
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT callback, const VkAllocationCallbacks* pAllocator) {
356+
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
357357
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
358358
if (func != nullptr) {
359-
func(instance, callback, pAllocator);
359+
func(instance, debugMessenger, pAllocator);
360360
}
361361
}
362362
```
@@ -367,7 +367,7 @@ outside the class. We can then call it in the `cleanup` function:
367367
```c++
368368
void cleanup() {
369369
if (enableValidationLayers) {
370-
DestroyDebugUtilsMessengerEXT(instance, callback, nullptr);
370+
DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr);
371371
}
372372
373373
vkDestroyInstance(instance, nullptr);

code/02_validation_layers.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ const bool enableValidationLayers = false;
2020
const bool enableValidationLayers = true;
2121
#endif
2222

23-
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pCallback) {
23+
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) {
2424
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
2525
if (func != nullptr) {
26-
return func(instance, pCreateInfo, pAllocator, pCallback);
26+
return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
2727
} else {
2828
return VK_ERROR_EXTENSION_NOT_PRESENT;
2929
}
3030
}
3131

32-
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT callback, const VkAllocationCallbacks* pAllocator) {
32+
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
3333
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
3434
if (func != nullptr) {
35-
func(instance, callback, pAllocator);
35+
func(instance, debugMessenger, pAllocator);
3636
}
3737
}
3838

@@ -49,7 +49,7 @@ class HelloTriangleApplication {
4949
GLFWwindow* window;
5050

5151
VkInstance instance;
52-
VkDebugUtilsMessengerEXT callback;
52+
VkDebugUtilsMessengerEXT debugMessenger;
5353

5454
void initWindow() {
5555
glfwInit();
@@ -62,7 +62,7 @@ class HelloTriangleApplication {
6262

6363
void initVulkan() {
6464
createInstance();
65-
setupDebugCallback();
65+
setupDebugMessenger();
6666
}
6767

6868
void mainLoop() {
@@ -73,7 +73,7 @@ class HelloTriangleApplication {
7373

7474
void cleanup() {
7575
if (enableValidationLayers) {
76-
DestroyDebugUtilsMessengerEXT(instance, callback, nullptr);
76+
DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr);
7777
}
7878

7979
vkDestroyInstance(instance, nullptr);
@@ -116,7 +116,7 @@ class HelloTriangleApplication {
116116
}
117117
}
118118

119-
void setupDebugCallback() {
119+
void setupDebugMessenger() {
120120
if (!enableValidationLayers) return;
121121

122122
VkDebugUtilsMessengerCreateInfoEXT createInfo = {};
@@ -125,8 +125,8 @@ class HelloTriangleApplication {
125125
createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
126126
createInfo.pfnUserCallback = debugCallback;
127127

128-
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &callback) != VK_SUCCESS) {
129-
throw std::runtime_error("failed to set up debug callback!");
128+
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger) != VK_SUCCESS) {
129+
throw std::runtime_error("failed to set up debug messenger!");
130130
}
131131
}
132132

code/03_physical_device_selection.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ const bool enableValidationLayers = false;
2121
const bool enableValidationLayers = true;
2222
#endif
2323

24-
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pCallback) {
24+
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) {
2525
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
2626
if (func != nullptr) {
27-
return func(instance, pCreateInfo, pAllocator, pCallback);
27+
return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
2828
} else {
2929
return VK_ERROR_EXTENSION_NOT_PRESENT;
3030
}
3131
}
3232

33-
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT callback, const VkAllocationCallbacks* pAllocator) {
33+
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
3434
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
3535
if (func != nullptr) {
36-
func(instance, callback, pAllocator);
36+
func(instance, debugMessenger, pAllocator);
3737
}
3838
}
3939

@@ -58,7 +58,7 @@ class HelloTriangleApplication {
5858
GLFWwindow* window;
5959

6060
VkInstance instance;
61-
VkDebugUtilsMessengerEXT callback;
61+
VkDebugUtilsMessengerEXT debugMessenger;
6262

6363
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
6464

@@ -73,7 +73,7 @@ class HelloTriangleApplication {
7373

7474
void initVulkan() {
7575
createInstance();
76-
setupDebugCallback();
76+
setupDebugMessenger();
7777
pickPhysicalDevice();
7878
}
7979

@@ -85,7 +85,7 @@ class HelloTriangleApplication {
8585

8686
void cleanup() {
8787
if (enableValidationLayers) {
88-
DestroyDebugUtilsMessengerEXT(instance, callback, nullptr);
88+
DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr);
8989
}
9090

9191
vkDestroyInstance(instance, nullptr);
@@ -128,7 +128,7 @@ class HelloTriangleApplication {
128128
}
129129
}
130130

131-
void setupDebugCallback() {
131+
void setupDebugMessenger() {
132132
if (!enableValidationLayers) return;
133133

134134
VkDebugUtilsMessengerCreateInfoEXT createInfo = {};
@@ -137,8 +137,8 @@ class HelloTriangleApplication {
137137
createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
138138
createInfo.pfnUserCallback = debugCallback;
139139

140-
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &callback) != VK_SUCCESS) {
141-
throw std::runtime_error("failed to set up debug callback!");
140+
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger) != VK_SUCCESS) {
141+
throw std::runtime_error("failed to set up debug messenger!");
142142
}
143143
}
144144

code/04_logical_device.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ const bool enableValidationLayers = false;
2121
const bool enableValidationLayers = true;
2222
#endif
2323

24-
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pCallback) {
24+
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) {
2525
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
2626
if (func != nullptr) {
27-
return func(instance, pCreateInfo, pAllocator, pCallback);
27+
return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
2828
} else {
2929
return VK_ERROR_EXTENSION_NOT_PRESENT;
3030
}
3131
}
3232

33-
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT callback, const VkAllocationCallbacks* pAllocator) {
33+
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
3434
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
3535
if (func != nullptr) {
36-
func(instance, callback, pAllocator);
36+
func(instance, debugMessenger, pAllocator);
3737
}
3838
}
3939

@@ -58,7 +58,7 @@ class HelloTriangleApplication {
5858
GLFWwindow* window;
5959

6060
VkInstance instance;
61-
VkDebugUtilsMessengerEXT callback;
61+
VkDebugUtilsMessengerEXT debugMessenger;
6262

6363
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
6464
VkDevice device;
@@ -76,7 +76,7 @@ class HelloTriangleApplication {
7676

7777
void initVulkan() {
7878
createInstance();
79-
setupDebugCallback();
79+
setupDebugMessenger();
8080
pickPhysicalDevice();
8181
createLogicalDevice();
8282
}
@@ -91,7 +91,7 @@ class HelloTriangleApplication {
9191
vkDestroyDevice(device, nullptr);
9292

9393
if (enableValidationLayers) {
94-
DestroyDebugUtilsMessengerEXT(instance, callback, nullptr);
94+
DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr);
9595
}
9696

9797
vkDestroyInstance(instance, nullptr);
@@ -134,7 +134,7 @@ class HelloTriangleApplication {
134134
}
135135
}
136136

137-
void setupDebugCallback() {
137+
void setupDebugMessenger() {
138138
if (!enableValidationLayers) return;
139139

140140
VkDebugUtilsMessengerCreateInfoEXT createInfo = {};
@@ -143,8 +143,8 @@ class HelloTriangleApplication {
143143
createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
144144
createInfo.pfnUserCallback = debugCallback;
145145

146-
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &callback) != VK_SUCCESS) {
147-
throw std::runtime_error("failed to set up debug callback!");
146+
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger) != VK_SUCCESS) {
147+
throw std::runtime_error("failed to set up debug messenger!");
148148
}
149149
}
150150

code/05_window_surface.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ const bool enableValidationLayers = false;
2222
const bool enableValidationLayers = true;
2323
#endif
2424

25-
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pCallback) {
25+
VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pDebugMessenger) {
2626
auto func = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkCreateDebugUtilsMessengerEXT");
2727
if (func != nullptr) {
28-
return func(instance, pCreateInfo, pAllocator, pCallback);
28+
return func(instance, pCreateInfo, pAllocator, pDebugMessenger);
2929
} else {
3030
return VK_ERROR_EXTENSION_NOT_PRESENT;
3131
}
3232
}
3333

34-
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT callback, const VkAllocationCallbacks* pAllocator) {
34+
void DestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks* pAllocator) {
3535
auto func = (PFN_vkDestroyDebugUtilsMessengerEXT) vkGetInstanceProcAddr(instance, "vkDestroyDebugUtilsMessengerEXT");
3636
if (func != nullptr) {
37-
func(instance, callback, pAllocator);
37+
func(instance, debugMessenger, pAllocator);
3838
}
3939
}
4040

@@ -60,7 +60,7 @@ class HelloTriangleApplication {
6060
GLFWwindow* window;
6161

6262
VkInstance instance;
63-
VkDebugUtilsMessengerEXT callback;
63+
VkDebugUtilsMessengerEXT debugMessenger;
6464
VkSurfaceKHR surface;
6565

6666
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
@@ -80,7 +80,7 @@ class HelloTriangleApplication {
8080

8181
void initVulkan() {
8282
createInstance();
83-
setupDebugCallback();
83+
setupDebugMessenger();
8484
createSurface();
8585
pickPhysicalDevice();
8686
createLogicalDevice();
@@ -96,7 +96,7 @@ class HelloTriangleApplication {
9696
vkDestroyDevice(device, nullptr);
9797

9898
if (enableValidationLayers) {
99-
DestroyDebugUtilsMessengerEXT(instance, callback, nullptr);
99+
DestroyDebugUtilsMessengerEXT(instance, debugMessenger, nullptr);
100100
}
101101

102102
vkDestroySurfaceKHR(instance, surface, nullptr);
@@ -140,7 +140,7 @@ class HelloTriangleApplication {
140140
}
141141
}
142142

143-
void setupDebugCallback() {
143+
void setupDebugMessenger() {
144144
if (!enableValidationLayers) return;
145145

146146
VkDebugUtilsMessengerCreateInfoEXT createInfo = {};
@@ -149,8 +149,8 @@ class HelloTriangleApplication {
149149
createInfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
150150
createInfo.pfnUserCallback = debugCallback;
151151

152-
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &callback) != VK_SUCCESS) {
153-
throw std::runtime_error("failed to set up debug callback!");
152+
if (CreateDebugUtilsMessengerEXT(instance, &createInfo, nullptr, &debugMessenger) != VK_SUCCESS) {
153+
throw std::runtime_error("failed to set up debug messenger!");
154154
}
155155
}
156156

0 commit comments

Comments
 (0)