From d5b393a2686962413d3beda231ab3290c96570d3 Mon Sep 17 00:00:00 2001 From: Yuri Rubinsky Date: Sat, 22 Jun 2024 16:15:40 +0300 Subject: [PATCH] Fix crash on shader constant initialization on MinGW compiler --- servers/rendering/shader_language.cpp | 10 +++++++--- servers/rendering/shader_language.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/servers/rendering/shader_language.cpp b/servers/rendering/shader_language.cpp index 9aa54d0bb77..f5f635af881 100644 --- a/servers/rendering/shader_language.cpp +++ b/servers/rendering/shader_language.cpp @@ -1445,8 +1445,12 @@ bool ShaderLanguage::_find_identifier(const BlockNode *p_block, bool p_allow_rea *r_struct_name = shader->constants[p_identifier].struct_name; } if (r_constant_value) { - if (shader->constants[p_identifier].initializer && shader->constants[p_identifier].initializer->values.size() == 1) { - *r_constant_value = shader->constants[p_identifier].initializer->values[0]; + if (shader->constants[p_identifier].initializer && shader->constants[p_identifier].initializer->type == Node::NODE_TYPE_CONSTANT) { + ConstantNode *cnode = static_cast(shader->constants[p_identifier].initializer); + + if (cnode->values.size() == 1) { + *r_constant_value = cnode->values[0]; + } } } if (r_type) { @@ -9443,7 +9447,7 @@ Error ShaderLanguage::_parse_shader(const HashMap &p_f } } - constant.initializer = static_cast(expr); + constant.initializer = expr; if (!_compare_datatypes(type, struct_name, 0, expr->get_datatype(), expr->get_datatype_name(), expr->get_array_size())) { return ERR_PARSE_ERROR; diff --git a/servers/rendering/shader_language.h b/servers/rendering/shader_language.h index 5615d7f457f..40d95b73657 100644 --- a/servers/rendering/shader_language.h +++ b/servers/rendering/shader_language.h @@ -620,7 +620,7 @@ public: DataType type; StringName struct_name; DataPrecision precision; - ConstantNode *initializer = nullptr; + Node *initializer = nullptr; int array_size; };