diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-09-01 16:24:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-01 16:24:04 +0200 |
commit | 42f1ac2908563df965c2743f927a9dee7651f5a9 (patch) | |
tree | 18ba24d07767d7f818c34109b2bd2e0d2b4f5515 /servers | |
parent | cd438d56626c012f19257d8ac52eaa7c8033d4cf (diff) | |
parent | f495cede0b7e07e67c5342aa1a28a9cadfb28dc6 (diff) |
Merge pull request #21632 from JFonS/fix_15166
Fix handling of shader constants that caused crash, closes #15166
Diffstat (limited to 'servers')
-rw-r--r-- | servers/visual/shader_language.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index ffb130048f..9500f35732 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2368,9 +2368,9 @@ int ShaderLanguage::get_cardinality(DataType p_type) { 2, 3, 4, - 2, - 3, 4, + 9, + 16, 1, 1, 1, @@ -3307,7 +3307,9 @@ ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, Sha ERR_FAIL_COND_V(op->arguments[0]->type != Node::TYPE_VARIABLE, p_node); - DataType base = get_scalar_type(op->get_datatype()); + DataType type = op->get_datatype(); + DataType base = get_scalar_type(type); + int cardinality = get_cardinality(type); Vector<ConstantNode::Value> values; @@ -3318,19 +3320,9 @@ ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, Sha ConstantNode *cn = static_cast<ConstantNode *>(op->arguments[i]); if (get_scalar_type(cn->datatype) == base) { - - int cardinality = get_cardinality(op->arguments[i]->get_datatype()); - if (cn->values.size() == cardinality) { - - for (int j = 0; j < cn->values.size(); j++) { - values.push_back(cn->values[j]); - } - } else if (cn->values.size() == 1) { - - for (int j = 0; j < cardinality; j++) { - values.push_back(cn->values[0]); - } - } // else: should be filtered by the parser as it's an invalid constructor + for (int j = 0; j < cn->values.size(); j++) { + values.push_back(cn->values[j]); + } } else if (get_scalar_type(cn->datatype) == cn->datatype) { ConstantNode::Value v; @@ -3347,6 +3339,29 @@ ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, Sha } } + if (values.size() == 1) { + if (type >= TYPE_MAT2 && type <= TYPE_MAT4) { + ConstantNode::Value value = values[0]; + ConstantNode::Value zero; + zero.real = 0.0f; + int size = 2 + (type - TYPE_MAT2); + + values.clear(); + for (int i = 0; i < size; i++) { + for (int j = 0; j < size; j++) { + values.push_back(i == j ? value : zero); + } + } + } else { + for (int i = 1; i < cardinality; i++) { + values.push_back(values[0]); + } + } + } else if (values.size() != cardinality) { + ERR_PRINT("Failed to reduce expression, values and cardinality mismatch."); + return p_node; + } + ConstantNode *cn = alloc_node<ConstantNode>(); cn->datatype = op->get_datatype(); cn->values = values; |