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 crash when the comma used in for loop as a trailing #95350

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions servers/rendering/shader_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,13 @@ bool ShaderLanguage::_lookup_next(Token &r_tk) {
return false;
}

ShaderLanguage::Token ShaderLanguage::_peek() {
TkPos pre_pos = _get_tkpos();
Token tk = _get_token();
_set_tkpos(pre_pos);
return tk;
}

String ShaderLanguage::token_debug(const String &p_code) {
clear();

Expand Down Expand Up @@ -8080,6 +8087,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun
_set_error(RTR("The middle expression is expected to be a boolean operator."));
return ERR_PARSE_ERROR;
}
tk = _peek();
if (tk.type == TK_SEMICOLON) {
_set_error(vformat(RTR("Expected expression, found: '%s'."), get_token_text(tk)));
return ERR_PARSE_ERROR;
}
continue;
}
if (tk.type != TK_SEMICOLON) {
Expand All @@ -8088,6 +8100,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun
}
} else if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR_EXPRESSION) {
if (tk.type == TK_COMMA) {
tk = _peek();
if (tk.type == TK_PARENTHESIS_CLOSE) {
_set_error(vformat(RTR("Expected expression, found: '%s'."), get_token_text(tk)));
return ERR_PARSE_ERROR;
}
continue;
}
if (tk.type != TK_PARENTHESIS_CLOSE) {
Expand Down
1 change: 1 addition & 0 deletions servers/rendering/shader_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ class ShaderLanguage {
Token _make_token(TokenType p_type, const StringName &p_text = StringName());
Token _get_token();
bool _lookup_next(Token &r_tk);
Token _peek();

ShaderNode *shader = nullptr;

Expand Down
Loading