Merge pull request #93469 from Chaosus/shader_fix_crash

Fix crash on shader constant initialization on MinGW compiler
This commit is contained in:
Rémi Verschelde 2024-06-25 10:01:46 +02:00
commit 2e8ebb4a5e
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 8 additions and 4 deletions

View file

@ -1446,8 +1446,12 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea
*r_struct_name = shader->constants[p_identifier].struct_name; *r_struct_name = shader->constants[p_identifier].struct_name;
} }
if (r_constant_value) { if (r_constant_value) {
if (shader->constants[p_identifier].initializer && shader->constants[p_identifier].initializer->values.size() == 1) { if (shader->constants[p_identifier].initializer && shader->constants[p_identifier].initializer->type == Node::NODE_TYPE_CONSTANT) {
*r_constant_value = shader->constants[p_identifier].initializer->values[0]; ConstantNode *cnode = static_cast<ConstantNode *>(shader->constants[p_identifier].initializer);
if (cnode->values.size() == 1) {
*r_constant_value = cnode->values[0];
}
} }
} }
if (r_type) { if (r_type) {
@ -9541,7 +9545,7 @@ Error ShaderLanguage::_parse_shader(const HashMap<StringName, FunctionInfo> &p_f
} }
} }
constant.initializer = static_cast<ConstantNode *>(expr); constant.initializer = expr;
if (!_compare_datatypes(type, struct_name, 0, expr->get_datatype(), expr->get_datatype_name(), expr->get_array_size())) { if (!_compare_datatypes(type, struct_name, 0, expr->get_datatype(), expr->get_datatype_name(), expr->get_array_size())) {
return ERR_PARSE_ERROR; return ERR_PARSE_ERROR;

View file

@ -620,7 +620,7 @@ public:
DataType type; DataType type;
StringName struct_name; StringName struct_name;
DataPrecision precision; DataPrecision precision;
ConstantNode *initializer = nullptr; Node *initializer = nullptr;
int array_size; int array_size;
}; };