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

File doesn't exist @ dxCreateShader; When using long-string as raw-data in certain ways #3825

Open
1 task done
Daniheee opened this issue Oct 25, 2024 · 9 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@Daniheee
Copy link

Daniheee commented Oct 25, 2024

Describe the bug

So this is the main script, it obviously runs:

local shader1 = dxCreateShader([[
    float4 asd():COLOR0 {
        return 0;
    }

    technique {
        pass {
            PixelShader = compile ps_2_0 asd();
        }
    }
]])
iprint("shader1",shader1)

And if you remove the unnecessary whitespaces, it will still run perfectly:

local shader2 = dxCreateShader([[float4 asd():COLOR0{return 0;}technique {pass {PixelShader=compile ps_2_0 asd();}}]])
iprint("shader2",shader2)

But if you remove the extra whitespaces after the word 'technique' or 'pass,' it will throw a 'file doesn't exist' error:

local shader3 = dxCreateShader([[float4 asd():COLOR0{return 0;}technique {pass{PixelShader=compile ps_2_0 asd();}}]])
iprint("shader3",shader3)

OR

local shader4 = dxCreateShader([[float4 asd():COLOR0{return 0;}technique{pass {PixelShader=compile ps_2_0 asd();}}]])
iprint("shader4",shader4)

However, if you remove every whitespace, even after 'technique' and 'pass', it can still run, if you use it in a single line like this:

local shader5 = dxCreateShader([[
    float4 asd():COLOR0{return 0;}technique{pass{PixelShader=compile ps_2_0 asd();}}
]])
iprint("shader5",shader5)

This way the shader will be created again without any problem.

Steps to reproduce

  1. Just run the provided code snippets in any client side script.

Version

Client: v1.6-release-22780 (Windows 64-bit)
Server: v1.6-release-22780 (Windows 64-bit)

Additional context

My debug script results are shown here for better illustration:
Image

Relevant log output

No response

Security Policy

  • I have read and understood the Security Policy and this issue is not security related.
@Daniheee Daniheee added the bug Something isn't working label Oct 25, 2024
@TracerDS
Copy link
Contributor

TracerDS commented Oct 25, 2024

I see the issue

if (!bValidFilePath || (strFile[0] != '@' && strFile[0] != ':'))
{
    bIsRawData = strFile.find("\n") != std::string::npos;

    if (!bIsRawData)
    {
        bIsRawData = (strFile.find("technique ") != std::string::npos) && (strFile.find("pass ") != std::string::npos) &&
                     (strFile.find('{') != std::string::npos) && (strFile.find('}') != std::string::npos);
    }
}

Maybe it should not check for an end line 😆

@Lpsd
Copy link
Member

Lpsd commented Oct 25, 2024

That's how you check for a match from find - std::string::npos is -1, find returns -1 when no match is found.

If you're referring to the \n check, that's because a filename wouldn't have a newline, therefore it has to be raw data.

I think the solution here is to remove the checks for technique and pass entirely. You can't have curly braces in a Windows filename so there's no clash possible when curly braces are being checked to determine if it's raw data or not.

@TracerDS
Copy link
Contributor

That's how you check for a match from find - std::string::npos is -1, find returns -1 when no match is found.

If you're referring to the \n check, that's because a filename wouldn't have a newline, therefore it has to be raw data.

I think the solution here is to remove the checks for technique and pass entirely. You can't have curly braces in a Windows filename so there's no clash possible when curly braces are being checked to determine if it's raw data or not.

Raw data can also not have new line as shown above. Thats not an ideal solution.
You also can have curly braces and semicolons in windows filenames

@Lpsd
Copy link
Member

Lpsd commented Oct 25, 2024

Raw data can have newlines. The author says the first example works, and I've also done it myself before.

You also can have curly braces and semicolons in windows filenames

Yeah true for some reason I thought they weren't allowed. Anyway, I think it's unlikely someone tries to load a shader with filename containing technique + pass + { + }

What is to stop them currently having a filename called technique pass { } anyway, makes sense to just remove the spaces from the find imo.

@TracerDS
Copy link
Contributor

cant we just have it all under one if statement?

bIsRawData = strFile.find("\n") != std::string::npos || (strFile.find("technique ") != std::string::npos
         && strFile.find("pass ") != std::string::npos && strFile.find('{') != std::string::npos
         && strFile.find('}') != std::string::npos);

@Lpsd
Copy link
Member

Lpsd commented Oct 25, 2024

Sounds fine, but you'll want to remove the spaces from technique and pass to resolve the author's issue.

@Fernando-A-Rocha
Copy link
Contributor

cant we just have it all under one if statement?

bIsRawData = strFile.find("\n") != std::string::npos || (strFile.find("technique ") != std::string::npos
&& strFile.find("pass ") != std::string::npos && strFile.find('{') != std::string::npos
&& strFile.find('}') != std::string::npos);

Wouldn't finding for { and } be enough to identify raw data instead of path?

@TracerDS
Copy link
Contributor

Wouldn't finding for { and } be enough to identify raw data instead of path?

{}.txt is a valid file name. If {}.txt is a valid file name then {} is also a valid file name. You can see the issue here.
The best way would be to introduce a boolean flag isRawData and then parse the shader according to that.

@Fernando-A-Rocha
Copy link
Contributor

My bad I didn't realize file names can have {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants