diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-02-21 09:43:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-21 09:43:51 +0100 |
commit | 3bb628d8fe26abad258a222a5e22b644e2b73a01 (patch) | |
tree | 0ecd10477abe901942d2f48d3b31a35b767a5945 /servers | |
parent | f6efa78173495e9e33bd5d3ebca91b55ab9f4587 (diff) | |
parent | f91e7e3ba491dd413be002a45e4720ea7e91cc58 (diff) |
Merge pull request #46272 from Chaosus/shader_fix_struct_crash
Prevents shader crash if passing invalid struct to the return statement
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/shader_language.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index e52d97e4d9..1f0cf5959f 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -5861,6 +5861,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_BUG; } + String return_struct_name = String(b->parent_function->return_struct_name); + ControlFlowNode *flow = alloc_node<ControlFlowNode>(); flow->flow_op = FLOW_OP_RETURN; @@ -5869,7 +5871,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun if (tk.type == TK_SEMICOLON) { //all is good if (b->parent_function->return_type != TYPE_VOID) { - _set_error("Expected return with expression of type '" + get_datatype_name(b->parent_function->return_type) + "'"); + _set_error("Expected return with an expression of type '" + (return_struct_name != "" ? return_struct_name : get_datatype_name(b->parent_function->return_type)) + "'"); return ERR_PARSE_ERROR; } } else { @@ -5879,8 +5881,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const FunctionInfo &p_fun return ERR_PARSE_ERROR; } - if (b->parent_function->return_type != expr->get_datatype()) { - _set_error("Expected return expression of type '" + get_datatype_name(b->parent_function->return_type) + "'"); + if (b->parent_function->return_type != expr->get_datatype() || return_struct_name != expr->get_datatype_name()) { + _set_error("Expected return with an expression of type '" + (return_struct_name != "" ? return_struct_name : get_datatype_name(b->parent_function->return_type)) + "'"); return ERR_PARSE_ERROR; } |