Skip to content

Commit

Permalink
Fix shader crash when the comma used in for loop as a trailing
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaosus committed Aug 10, 2024
1 parent c73ac74 commit d74749f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit d74749f

Please sign in to comment.