Skip to content

Commit

Permalink
Prevents shader crash if passing invalid struct to the return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaosus committed Feb 21, 2021
1 parent d4d7535 commit f91e7e3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions servers/rendering/shader_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -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;
}

Expand Down

0 comments on commit f91e7e3

Please sign in to comment.