From aa33db056a6f3fed2eab6092f23db7caaddb1cfc Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Thu, 26 Mar 2020 13:32:39 +0300 Subject: Prevent shader crash if multiple variables has been declared in 'for' --- servers/rendering/shader_language.cpp | 5 +++++ servers/rendering/shader_language.h | 1 + 2 files changed, 6 insertions(+) (limited to 'servers') diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index cf2a01c07c..300c38db22 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -5070,6 +5070,10 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Mapvariables[name] = var; if (tk.type == TK_COMMA) { + if (p_block->block_type == BlockNode::BLOCK_TYPE_FOR) { + _set_error("Multiple declarations in 'for' loop are not implemented yet."); + return ERR_PARSE_ERROR; + } tk = _get_token(); //another variable } else if (tk.type == TK_SEMICOLON) { @@ -5394,6 +5398,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Mapflow_op = FLOW_OP_FOR; BlockNode *init_block = alloc_node(); + init_block->block_type = BlockNode::BLOCK_TYPE_FOR; init_block->parent_block = p_block; init_block->single_statement = true; cf->blocks.push_back(init_block); diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index bdc15cc4aa..9124bee633 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -487,6 +487,7 @@ public: enum BlockType { BLOCK_TYPE_STANDART, + BLOCK_TYPE_FOR, BLOCK_TYPE_SWITCH, BLOCK_TYPE_CASE, BLOCK_TYPE_DEFAULT, -- cgit v1.2.3