0

I'm trying to include the spv shaders of my hello triangle program in the executable by adding like there. When I run the program I get the following assertion, throwed from debug_heap.cpp:

Expression: is_block_type_valid(header->block_use)

So there's my code:

Shaders.h:

#pragma once

const unsigned char triangle_frag_spv[] = {/* shader code */};
const unsigned triangle_frag_spv_size = sizeof(triangle_frag_spv);
const unsigned char triangle_vert_spv[] = {/* shader code */};
const unsigned triangle_vert_spv_size = sizeof(triangle_vert_spv);

Note: I removed the code of the shaders because it was very long.

If you want to see it go to Sascha Willems' Vulkan Samples and copy the SPVs hex value.

main.cpp:

#include <vulkan/vulkan.h>

#include "shaders.h"

extern "C" const unsigned char triangle_vert_spv[];
extern "C" const unsigned char triangle_frag_spv[];
extern "C" const unsigned triangle_vert_spv_size;
extern "C" const unsigned triangle_frag_spv_size;

...

std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages{};

shaderStages[0].module = loadSPIRVShader(triangle_vert_spv, triangle_vert_spv_size);
shaderStages[1].module = loadSPIRVShader(triangle_frag_spv, triangle_frag_spv_size);

...

VkShaderModule loadSPIRVShader(const unsigned char shaderCode[], const unsigned shaderSize)
{
    VkShaderModuleCreateInfo moduleCreateInfo{};
    moduleCreateInfo.sType    = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
    moduleCreateInfo.codeSize = shaderSize;
    moduleCreateInfo.pCode    = (uint32_t *) shaderCode;

    VkShaderModule shaderModule;
    VK_CHECK_RESULT(vkCreateShaderModule(device, &moduleCreateInfo, NULL, &shaderModule));

    delete[] shaderCode;

    return shaderModule;
}

So what is the proper way to embed the shaders in my executable and reference them?

Thebannedone
  • 55
  • 11
  • I think typically the tools dump array of `uint32_t`, not `unsigned char`s. Show at least first few values there in the example. And show here how you got it (in general on Stack Overflow do not link things that can be shown directly here). What's `debug_heap.cpp`, and wherefrom does it originate? – krOoze Apr 21 '21 at 16:17
  • Also `extern`ing something from a header is weird. Are you sure that does what you think it does? – krOoze Apr 21 '21 at 16:19
  • I would assume the main problem is you `delete[]` static variables. – krOoze Apr 21 '21 at 16:23
  • Thank's the problem was effectivly the ```delete[]``` You can post an answer if you want the reputation. – Thebannedone Apr 21 '21 at 16:26

1 Answers1

1

You are delete[]ing static variables. That is invalid thing to do.

Passing an arr[] is something like passing a pointer. If you are confused about C arrays (which is understandable), then try using std::arrays instead.

krOoze
  • 12,301
  • 1
  • 20
  • 34