Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#include does not handle absolute paths correctly #3611

Open
Ravbug opened this issue May 27, 2024 · 0 comments
Open

#include does not handle absolute paths correctly #3611

Ravbug opened this issue May 27, 2024 · 0 comments
Labels

Comments

@Ravbug
Copy link

Ravbug commented May 27, 2024

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:

virtual IncludeResult* readLocalPath(const char* headerName, const char* includerName, int depth)
{
// Discard popped include directories, and
// initialize when at parse-time first level.
directoryStack.resize(depth + externalLocalDirectoryCount);
if (depth == 1)
directoryStack.back() = getDirectory(includerName);
// Find a directory that works, using a reverse search of the include stack.
for (auto it = directoryStack.rbegin(); it != directoryStack.rend(); ++it) {
std::string path = *it + '/' + headerName;
std::replace(path.begin(), path.end(), '\\', '/');
std::ifstream file(path, std::ios_base::binary | std::ios_base::ate);
if (file) {
directoryStack.push_back(getDirectory(path));
includedFiles.insert(path);
return newIncludeResult(path, file, (int)file.tellg());
}
}
return nullptr;
}

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 
   // ...
    ```
Ravbug pushed a commit to RavEngine/RavEngine that referenced this issue May 27, 2024
~ fix bug in glslang surrounding handling of absolute paths in #include statements: KhronosGroup/glslang#3611
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants