Skip to content

Commit

Permalink
Merge pull request #50884 from Chaosus/fix_shader_crash
Browse files Browse the repository at this point in the history
Prevents shader crashing if varying assigned incorrectly by using compound assignment operators (*=, += etc.)
  • Loading branch information
akien-mga authored Jul 26, 2021
2 parents fdb74c7 + b47b3a9 commit 64dc58b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion servers/rendering/shader_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2820,6 +2820,20 @@ bool ShaderLanguage::is_token_operator(TokenType p_type) {
p_type == TK_COLON);
}

bool ShaderLanguage::is_token_operator_assign(TokenType p_type) {
return (p_type == TK_OP_ASSIGN ||
p_type == TK_OP_ASSIGN_ADD ||
p_type == TK_OP_ASSIGN_SUB ||
p_type == TK_OP_ASSIGN_MUL ||
p_type == TK_OP_ASSIGN_DIV ||
p_type == TK_OP_ASSIGN_MOD ||
p_type == TK_OP_ASSIGN_SHIFT_LEFT ||
p_type == TK_OP_ASSIGN_SHIFT_RIGHT ||
p_type == TK_OP_ASSIGN_BIT_AND ||
p_type == TK_OP_ASSIGN_BIT_OR ||
p_type == TK_OP_ASSIGN_BIT_XOR);
}

bool ShaderLanguage::convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value) {
if (p_constant->datatype == p_to_type) {
if (p_value) {
Expand Down Expand Up @@ -4240,7 +4254,8 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
Token next_token = _get_token();
_set_tkpos(prev_pos);
String error;
if (next_token.type == TK_OP_ASSIGN) {

if (is_token_operator_assign(next_token.type)) {
if (!_validate_varying_assign(shader->varyings[identifier], &error)) {
_set_error(error);
return nullptr;
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 @@ -766,6 +766,7 @@ class ShaderLanguage {
static String get_datatype_name(DataType p_type);
static bool is_token_nonvoid_datatype(TokenType p_type);
static bool is_token_operator(TokenType p_type);
static bool is_token_operator_assign(TokenType p_type);

static bool convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value = nullptr);
static DataType get_scalar_type(DataType p_type);
Expand Down

0 comments on commit 64dc58b

Please sign in to comment.