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

Some code in this tutorial leads to segfaults when using C (and other languages maby?) #292

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi,

I am not sure if you care about people using C, but I want to report it anyway.

Lets take this code for example (Vulkan tutorial, Vertex buffers -> Vertex buffer creation):

    VkBufferCreateInfo bufferInfo{};
    bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
    bufferInfo.size = sizeof(vertices[0]) * vertices.size();
    bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
    bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;

In C it looks something like that:

        VkBufferCreateInfo buffer_info;
        buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
        buffer_info.size = sizeof(vertecies);
        buffer_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
        buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;

However, this leads to a segfault inside the validation layers when calling vkCreateBuffer() without having pNext set. When looking at the other code of the tutorial, I could see that it also doesn't set the flags or pNext values, but that wasn't a problem (at least for me).

I have two suggestions to solve this: 1: You could say in the beggining of the tutorial something like Be aware, if you are using C, you will always need to set the flags and pNext field to 0 and NULL because there are no default values in C. (Not exactly like that, but you get the idea.) An FAQ entry with this text would proabtly also be a good alternative.

2: Always set the pNext and flags field. I think this might also be a good approch for other programming languages because people might run into similar problems when not setting these fields.

I think this might be a very nasty bug for people to fix and thats why I think it would be a good idea to do something about it. Myself, and probatly others too, assume that the code in the tutorial is correct.

-Lorenz

lewa-j commented 2 years ago

Just type VkBufferCreateInfo buffer_info = {0};

ghost commented 2 years ago

Thank you very much and sorry for my stupidness :). Didn't knew that that was exsisting in C, quite confusing, because I never saw that anywere. Anyways, thank you very much for your support!