Overv / VulkanTutorial

Tutorial for the Vulkan graphics and compute API
https://vulkan-tutorial.com
Creative Commons Attribution Share Alike 4.0 International
3.12k stars 513 forks source link

Code: Use uint32_t for WIDTH and HEIGHT to prevent narrowing conversion #174

Closed akien-mga closed 4 years ago

akien-mga commented 4 years ago

A warning would otherwise be raised from "Swap chain" onward when using GCC 9.3.0:

g++ -std=c++17 -o HelloTriangle main.cpp `pkg-config --static --libs glfw3` -lvulkan
main.cpp: In member function ‘VkExtent2D HelloTriangleApplication::chooseSwapExtent(const VkSurfaceCapabilitiesKHR&)’:
main.cpp:458:40: warning: narrowing conversion of ‘(int)((HelloTriangleApplication*)this)->HelloTriangleApplication::WIDTH’ from ‘int’ to ‘uint32_t’ {aka ‘unsigned int’} [-Wnarrowing]
  458 |             VkExtent2D actualExtent = {WIDTH, HEIGHT};
      |                                        ^~~~~
main.cpp:458:47: warning: narrowing conversion of ‘(int)((HelloTriangleApplication*)this)->HelloTriangleApplication::HEIGHT’ from ‘int’ to ‘uint32_t’ {aka ‘unsigned int’} [-Wnarrowing]
  458 |             VkExtent2D actualExtent = {WIDTH, HEIGHT};
      |                                               ^~~~~~

Note: I've replaced it everywhere, but I only tried it on my own code so far, currently at the end of the "Swap chain" step.

akien-mga commented 4 years ago

Note: I've replaced it everywhere, but I only tried it on my own code so far, currently at the end of the "Swap chain" step.

I now tested code/06_swap_chain_creation.cpp, code/16_swap_chain_recreation.cpp and code/29_multisampling.cpp with both GCC 9.3.0 and Clang 10.0.0, and they build fine without warning (at least when using default warning level / no custom -W flag).

Overv commented 4 years ago

Nice! Thanks for the fix.