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

Fix shader language preprocessor include marker handling #81381

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

bitsawer
Copy link
Member

@bitsawer bitsawer commented Sep 6, 2023

When the shader preprocessor handles include directives, it adds enter and exit markers to the shader code, like this:

@@>some_file.gdshaderinc
//Included shader code goes here.
@@<

The actual shader compiler tokenizer then handles these markers and pushes and pops line and file remapping (include_positions). These are used for better file and line number error reporting. However, in some specific circumstances the tokenizer can backtrack the current statement and process same code multiple times. In this case, it happens when an include is used inside a function code block immediately followed by an assignment. In that case, it also processes the include marker multiple times and makes the remapping stack unbalanced.

This PR makes each include marker unique by also adding the file name after the @@< marker and only manipulates the include_positions stack once per marker. This makes sure the stack stays balanced.

@bitsawer bitsawer added this to the 4.2 milestone Sep 6, 2023
@bitsawer bitsawer requested a review from a team as a code owner September 6, 2023 14:16
@akien-mga akien-mga requested a review from a team September 6, 2023 15:21
@jitspoe
Copy link
Contributor

jitspoe commented Sep 7, 2023

Oh, nice. Thanks for the quick fix! I wish I understood the shader parsing code well enough to know if this was a good approach, but my brain kind of 404'd while looking through it.

@akien-mga akien-mga merged commit e25408d into godotengine:master Sep 26, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Invalid include exit hint @@< without matching enter hint." error setting built-ins after shader #include
3 participants