Skip to content

Commit

Permalink
fixed a bug that Init after error position.
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzboy committed Feb 17, 2023
1 parent 532421f commit d256807
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions glsl2spv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ extern "C"

uint32_t *spv_data;
uint32_t spv_length;
uint32_t shader_stage;

ShaderStageData input,output;
ShaderResourceData resource[VK_DESCRIPTOR_TYPE_COUNT];
Expand All @@ -338,18 +337,6 @@ extern "C"
memset(this,0,sizeof(SPVData));
}

void Clear()
{
for(uint32_t i=0;i<VK_DESCRIPTOR_TYPE_COUNT;i++)
delete[] resource[i].items;

delete[] push_constant.items;
delete[] subpass_input.items;

delete[] input.items;
delete[] output.items;
}

public:

SPVData(const char *l,const char *dl)
Expand All @@ -370,6 +357,8 @@ extern "C"

SPVData(const std::vector<uint32_t> &spirv)
{
Init();

result=true;

log=nullptr;
Expand All @@ -379,13 +368,18 @@ extern "C"
spv_data=new uint32_t[spv_length];
spv_length*=sizeof(uint32_t);
memcpy(spv_data,spirv.data(),spv_length);

Init();
}

~SPVData()
{
Clear();
{
for(uint32_t i=0;i<VK_DESCRIPTOR_TYPE_COUNT;i++)
delete[] resource[i].items;

delete[] push_constant.items;
delete[] subpass_input.items;

delete[] input.items;
delete[] output.items;

delete[] log;
delete[] debug_log;
Expand Down Expand Up @@ -488,8 +482,8 @@ extern "C"
}

SPVData *Shader2SPV(
const uint32_t shader_stage,
const char * shader_source,
const uint32_t shader_stage,
const char * shader_source,
const CompileInfo * compile_info)
{
EShLanguage stage = FindLanguage((VkShaderStageFlagBits)shader_stage);
Expand Down Expand Up @@ -521,7 +515,7 @@ extern "C"
for (uint32_t i = 0; i < compile_info->includes_count; i++)
{
includer.pushExternalLocalDirectory(compile_info->includes[i]);
}
}
}

if(compile_info->preamble)
Expand Down Expand Up @@ -558,8 +552,6 @@ extern "C"
glslang::GlslangToSpv(*program.getIntermediate(stage),spirv);

SPVData *spv=new SPVData(spirv);

spv->shader_stage = shader_stage;

{
ShaderParse sp(spirv.data(),(uint32_t)spirv.size()*sizeof(uint32_t));
Expand Down

0 comments on commit d256807

Please sign in to comment.