Reputation: 65
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?
Upvotes: 0
Views: 126
Reputation: 13306
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::array
s instead.
Upvotes: 1