Prevent shader crash if name of variable overrides function name

(cherry picked from commit 76324bec8d)
This commit is contained in:
Yuri Roubinsky 2019-10-06 20:35:41 +03:00 committed by Rémi Verschelde
parent 8b4eea3d6d
commit c1cabb0bf5
1 changed files with 10 additions and 0 deletions

View File

@ -2848,6 +2848,16 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons
bool ok = _parse_function_arguments(p_block, p_builtin_types, func, &carg); bool ok = _parse_function_arguments(p_block, p_builtin_types, func, &carg);
// Check if block has a variable with the same name as function to prevent shader crash.
ShaderLanguage::BlockNode *bnode = p_block;
while (bnode) {
if (bnode->variables.has(name)) {
_set_error("Expected function name");
return NULL;
}
bnode = bnode->parent_block;
}
//test if function was parsed first //test if function was parsed first
for (int i = 0; i < shader->functions.size(); i++) { for (int i = 0; i < shader->functions.size(); i++) {
if (shader->functions[i].name == name) { if (shader->functions[i].name == name) {