summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/object/object.cpp5
-rw-r--r--core/object/object.h4
-rw-r--r--core/object/script_language.cpp7
-rw-r--r--core/variant/dictionary.cpp7
-rw-r--r--core/variant/dictionary.h1
-rw-r--r--core/variant/variant_call.cpp1
6 files changed, 20 insertions, 5 deletions
diff --git a/core/object/object.cpp b/core/object/object.cpp
index b34182cdaa..6a5a9efefa 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -2258,8 +2258,9 @@ void ObjectDB::cleanup() {
extra_info = " - Resource path: " + String(resource_get_path->call(obj, nullptr, 0, call_error));
}
- uint64_t id = uint64_t(i) | (uint64_t(object_slots[i].validator) << OBJECTDB_VALIDATOR_BITS) | (object_slots[i].is_ref_counted ? OBJECTDB_REFERENCE_BIT : 0);
- print_line("Leaked instance: " + String(obj->get_class()) + ":" + itos(id) + extra_info);
+ uint64_t id = uint64_t(i) | (uint64_t(object_slots[i].validator) << OBJECTDB_SLOT_MAX_COUNT_BITS) | (object_slots[i].is_ref_counted ? OBJECTDB_REFERENCE_BIT : 0);
+ DEV_ASSERT(id == (uint64_t)obj->get_instance_id()); // We could just use the id from the object, but this check may help catching memory corruption catastrophes.
+ print_line("Leaked instance: " + String(obj->get_class()) + ":" + uitos(id) + extra_info);
count--;
}
diff --git a/core/object/object.h b/core/object/object.h
index f97691841f..cb1495296d 100644
--- a/core/object/object.h
+++ b/core/object/object.h
@@ -798,12 +798,12 @@ public:
template <class T>
static T *cast_to(Object *p_object) {
- return dynamic_cast<T *>(p_object);
+ return p_object ? dynamic_cast<T *>(p_object) : nullptr;
}
template <class T>
static const T *cast_to(const Object *p_object) {
- return dynamic_cast<const T *>(p_object);
+ return p_object ? dynamic_cast<const T *>(p_object) : nullptr;
}
enum {
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index d358a8d2a0..693c6819d4 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -715,7 +715,12 @@ void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name,
}
}
if (!found) {
- properties.push_back(PropertyInfo(p_value.get_type(), p_name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE));
+ PropertyHint hint = PROPERTY_HINT_NONE;
+ const Object *obj = p_value.get_validated_object();
+ if (obj && obj->is_class("Node")) {
+ hint = PROPERTY_HINT_NODE_TYPE;
+ }
+ properties.push_back(PropertyInfo(p_value.get_type(), p_name, hint, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE));
}
}
diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp
index 9f65a73c6f..7416101d51 100644
--- a/core/variant/dictionary.cpp
+++ b/core/variant/dictionary.cpp
@@ -249,6 +249,7 @@ void Dictionary::clear() {
}
void Dictionary::merge(const Dictionary &p_dictionary, bool p_overwrite) {
+ ERR_FAIL_COND_MSG(_p->read_only, "Dictionary is in read-only state.");
for (const KeyValue<Variant, Variant> &E : p_dictionary._p->variant_map) {
if (p_overwrite || !has(E.key)) {
operator[](E.key) = E.value;
@@ -256,6 +257,12 @@ void Dictionary::merge(const Dictionary &p_dictionary, bool p_overwrite) {
}
}
+Dictionary Dictionary::merged(const Dictionary &p_dictionary, bool p_overwrite) const {
+ Dictionary ret = duplicate();
+ ret.merge(p_dictionary, p_overwrite);
+ return ret;
+}
+
void Dictionary::_unref() const {
ERR_FAIL_NULL(_p);
if (_p->refcount.unref()) {
diff --git a/core/variant/dictionary.h b/core/variant/dictionary.h
index f94a0da80a..67178ee7b7 100644
--- a/core/variant/dictionary.h
+++ b/core/variant/dictionary.h
@@ -64,6 +64,7 @@ public:
bool is_empty() const;
void clear();
void merge(const Dictionary &p_dictionary, bool p_overwrite = false);
+ Dictionary merged(const Dictionary &p_dictionary, bool p_overwrite = false) const;
bool has(const Variant &p_key) const;
bool has_all(const Array &p_keys) const;
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 543ee1135f..060ea007ff 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -2205,6 +2205,7 @@ static void _register_variant_builtin_methods() {
bind_method(Dictionary, is_empty, sarray(), varray());
bind_method(Dictionary, clear, sarray(), varray());
bind_method(Dictionary, merge, sarray("dictionary", "overwrite"), varray(false));
+ bind_method(Dictionary, merged, sarray("dictionary", "overwrite"), varray(false));
bind_method(Dictionary, has, sarray("key"), varray());
bind_method(Dictionary, has_all, sarray("keys"), varray());
bind_method(Dictionary, find_key, sarray("value"), varray());