KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.95k stars 819 forks source link

Crash when using -u on the command line #1536

Closed anomalous42 closed 5 years ago

anomalous42 commented 5 years ago

I'm seeing a crash when using -u on the command line.

The full command line that I'm using is: -e main --rsb 1 -H -V --amb --aml -unormal:3 -ucolour:1 test.vert.hlsl

The contents of test.vert.hlsl is:

float4 main(float3 colour : COLOUR, float3 normal : NORMAL) : SV_Position
{
    return float4(colour + normal, 1);
}

It looks like it's failing to construct a TString due to a null TPoolAllocator. Call stack:

    glslangValidator.exe!glslang::TPoolAllocator::allocate(unsigned int numBytes) Line 245  C++
    glslangValidator.exe!glslang::pool_allocator<std::_Container_proxy>::allocate(unsigned int n) Line 288  C++
    glslangValidator.exe!std::_String_alloc<std::_String_base_types<char,glslang::pool_allocator<char> > >::_Alloc_proxy() Line 1991    C++
    glslangValidator.exe!std::_String_alloc<std::_String_base_types<char,glslang::pool_allocator<char> > >::_String_alloc<std::_String_base_types<char,glslang::pool_allocator<char> > >() Line 1936    C++
    glslangValidator.exe!std::basic_string<char,std::char_traits<char>,glslang::pool_allocator<char> >::basic_string<char,std::char_traits<char>,glslang::pool_allocator<char> >(const char * const _Ptr) Line 2182 C++
    glslangValidator.exe!glslang::TShader::addUniformLocationOverride(const char * name, int loc) Line 1764 C++
    glslangValidator.exe!CompileAndLinkShaderUnits(std::vector<ShaderCompUnit,std::allocator<ShaderCompUnit> > compUnits) Line 932  C++
    glslangValidator.exe!CompileAndLinkShaderFiles(glslang::TWorklist & Worklist) Line 1111 C++
    glslangValidator.exe!singleMain() Line 1182 C++
    glslangValidator.exe!main(int argc, char * * argv) Line 1236    C++
johnkslang commented 5 years ago

This is in code recently added @bpeel, to get more eyes on it.

It looks like it is doing pool-based memory allocation too early. I'm looking at a work around.

johnkslang commented 5 years ago

The interfaces were all 'const char*' anyway, so using 'TString' was not necessary. I changed it to just use std::string. However, it's not clear it's all working correctly anyway. If so, can have a new issue for that.