From ac547031d54f331a5399b676ecf316a10b3cb83e Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Sun, 21 Feb 2021 07:35:09 +0300 Subject: [PATCH] Prevents shader crash if passing invalid struct to the return statement --- servers/visual/shader_language.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index c1759251ed..8f55f39e06 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -5335,6 +5335,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Mapparent_function->return_struct_name); + ControlFlowNode *flow = alloc_node(); flow->flow_op = FLOW_OP_RETURN; @@ -5343,7 +5345,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Mapparent_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 { @@ -5353,8 +5355,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Mapparent_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; }