Overv / VulkanTutorial

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

Possibly erroneous code in "Binding the vertex buffer" section of Vertex buffer creation #347

Closed Calinou closed 11 months ago

Calinou commented 11 months ago

In Vertex buffer creation, I had to change the following for the code to build (and successfully display a triangle with no validation errors):

vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);

-VkBuffer vertexBuffers[] = {vertexBuffer};
+VkBuffer* vertexBuffers = { &vertexBuffer };
VkDeviceSize offsets[] = {0};
vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets);

vkCmdDraw(commandBuffer, static_cast<uint32_t>(vertices.size()), 1, 0, 0);

With the original code, I get this error:

sccache c++ -Ihello_triangle.p -I. -I.. -I/usr/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++20 -O0 -g -MD -MQ hello_triangle.p/main.cpp.o -MF hello_triangle.p/main.cpp.o.d -o hello_triangle.p/main.cpp.o -c ../main.cpp
../main.cpp: In member function ‘void HelloTriangleApplication::recordCommandBuffer(VkCommandBuffer, uint32_t)’:
../main.cpp:975:38: error: cannot convert ‘VkBuffer_T**’ to ‘VkBuffer’ {aka ‘VkBuffer_T*’} in initialization
  975 |         VkBuffer vertexBuffers[] = { &vertexBuffer };
      |                                      ^~~~~~~~~~~~~~
      |                                      |
      |                                      VkBuffer_T**

Is this something that changed in the Vulkan specification? I'm using GCC 13.1.1 on Linux (using Meson configured in C++20).

You can see my full code here: https://github.com/Calinou/vulkan-tutorial

Overv commented 11 months ago

Your code contains a small mistake:

VkBuffer vertexBuffers[] = { &vertexBuffer };

The & should not be there and isn't in the original tutorial code.

Calinou commented 11 months ago

Your code contains a small mistake:

VkBuffer vertexBuffers[] = { &vertexBuffer };

The & should not be there and isn't in the original tutorial code.

I see, it works with the & removed :slightly_smiling_face: Thanks!