KhronosGroup / glslang

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

#include does not handle absolute paths correctly #3611

Open Ravbug opened 1 month ago

Ravbug commented 1 month ago

The following shader does not compile, despite the included file existing:

#include "C:\users\Admin\Desktop\file.glsl"

void main(){}

This is because quoted includes get passed to readLocalPath, which assumes the path is local and transforms it before trying to read it: https://github.com/KhronosGroup/glslang/blob/1cad045cc2bf79c976e1d7001ac71644f6cb29a8/StandAlone/DirStackFileIncluder.h#L103-L124

I fixed this in my copy by changing readLocalPath to check headerName as-is, in case it's an absolute path, before transforming it as a local path:

virtual IncludeResult* readLocalPath(const char* headerName, const char* includerName, int depth)
{
    // first check for absolute paths:
    std::ifstream file(headerName, std::ios_base::binary | std::ios_base::ate);
    if (file) {
        directoryStack.push_back(getDirectory(headerName));
        includedFiles.insert(headerName);
        return newIncludeResult(headerName, file, (int)file.tellg());
    }

    // Discard popped include directories, and 
   // ...