diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2022-01-06 21:46:59 +0100 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2022-01-06 21:46:59 +0100 |
commit | 7a66af274ab743a6045a72269e3f616254478c7a (patch) | |
tree | 2a710d198adb5dc427ff8ba4fa81647ea69d7fac /scene/property_utils.cpp | |
parent | 393a44b275152c660b2010598661b2730c9c60a8 (diff) |
Fix too broad assumption of null property defaults
Diffstat (limited to 'scene/property_utils.cpp')
-rw-r--r-- | scene/property_utils.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/scene/property_utils.cpp b/scene/property_utils.cpp index 4acb43cdb7..2540a633a9 100644 --- a/scene/property_utils.cpp +++ b/scene/property_utils.cpp @@ -111,15 +111,37 @@ Variant PropertyUtils::get_property_default_value(const Object *p_object, const } // Fall back to the default from the native class - if (r_is_class_default) { - *r_is_class_default = true; - } - // This is saying that properties not registered in the class DB are considered to have a default value of null - // (that covers cases like synthetic properties in the style of whatever/0, whatever/1, which may not have a value in any ancestor). - if (r_is_valid) { - *r_is_valid = true; + { + if (r_is_class_default) { + *r_is_class_default = true; + } + bool valid = false; + Variant value = ClassDB::class_get_default_property_value(p_object->get_class_name(), p_property, &valid); + if (valid) { + if (r_is_valid) { + *r_is_valid = true; + } + return value; + } else { + // Heuristically check if this is a synthetic property (whatever/0, whatever/1, etc.) + // because they are not in the class DB yet must have a default (null). + String prop_str = String(p_property); + int p = prop_str.rfind("/"); + if (p != -1 && p < prop_str.length() - 1) { + bool all_digits = true; + for (int i = p + 1; i < prop_str.length(); i++) { + if (prop_str[i] < '0' || prop_str[i] > '9') { + all_digits = false; + break; + } + } + if (r_is_valid) { + *r_is_valid = all_digits; + } + } + return Variant(); + } } - return ClassDB::class_get_default_property_value(p_object->get_class_name(), p_property); } // Like SceneState::PackState, but using a raw pointer to avoid the cost of |