diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-07-26 15:39:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 15:39:59 +0200 |
commit | 64dc58bfba55c4e5dcdce18bf848abf43332afd0 (patch) | |
tree | 8e551de7f7418a6244d11c01af323cce5d41fd6f | |
parent | fdb74c7512b33d27a2fda58e64f97e936c9eac7c (diff) | |
parent | b47b3a9957e8afcbc7421002d6a6e3a273a2b9b0 (diff) |
Merge pull request #50884 from Chaosus/fix_shader_crash
Prevents shader crashing if varying assigned incorrectly by using compound assignment operators (*=, += etc.)
-rw-r--r-- | servers/rendering/shader_language.cpp | 17 | ||||
-rw-r--r-- | servers/rendering/shader_language.h | 1 |
2 files changed, 17 insertions, 1 deletions
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 8f4f248276..c9bdec688d 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -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) { @@ -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; diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index 59c6e19338..c02d6c47ec 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -766,6 +766,7 @@ public: 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); |