From 031f763d4fda4e0dbcdf90a170aad3124c50c062 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 20 Aug 2018 16:35:36 -0300 Subject: [PATCH] Crash fixes for material and animtree --- core/object.cpp | 16 +++++++++++----- core/object.h | 2 ++ core/resource.cpp | 6 ++++-- scene/animation/animation_blend_tree.cpp | 5 +++++ scene/resources/material.cpp | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/core/object.cpp b/core/object.cpp index 4b2869b3736..76226d113ab 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1530,6 +1530,10 @@ bool Object::is_connected(const StringName &p_signal, Object *p_to_object, const void Object::disconnect(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) { + _disconnect(p_signal, p_to_object, p_to_method); +} +void Object::_disconnect(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, bool p_force) { + ERR_FAIL_NULL(p_to_object); Signal *s = signal_map.getptr(p_signal); if (!s) { @@ -1550,9 +1554,11 @@ void Object::disconnect(const StringName &p_signal, Object *p_to_object, const S Signal::Slot *slot = &s->slot_map[target]; - slot->reference_count--; // by default is zero, if it was not referenced it will go below it - if (slot->reference_count >= 0) { - return; + if (!p_force) { + slot->reference_count--; // by default is zero, if it was not referenced it will go below it + if (slot->reference_count >= 0) { + return; + } } p_to_object->connections.erase(slot->cE); @@ -1965,13 +1971,13 @@ Object::~Object() { Connection &c = E->get(); ERR_CONTINUE(c.source != this); //bug? - this->disconnect(c.signal, c.target, c.method); + this->_disconnect(c.signal, c.target, c.method, true); } while (connections.size()) { Connection c = connections.front()->get(); - c.source->disconnect(c.signal, c.target, c.method); + c.source->_disconnect(c.signal, c.target, c.method, true); } ObjectDB::remove_instance(this); diff --git a/core/object.h b/core/object.h index 52c9c509ab9..d7413713061 100644 --- a/core/object.h +++ b/core/object.h @@ -551,6 +551,8 @@ protected: friend class ClassDB; virtual void _validate_property(PropertyInfo &property) const; + void _disconnect(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, bool p_force = false); + public: //should be protected, but bug in clang++ static void initialize_class(); _FORCE_INLINE_ static void register_custom_data_to_otdb(){}; diff --git a/core/resource.cpp b/core/resource.cpp index 87ff4d3c2a1..3078eb135a1 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -151,7 +151,7 @@ Ref Resource::duplicate_for_local_scene(Node *p_for_scene, Map plist; get_property_list(&plist); - Resource *r = (Resource *)ClassDB::instance(get_class()); + Resource *r = Object::cast_to(ClassDB::instance(get_class())); ERR_FAIL_COND_V(!r, Ref()); r->local_scene = p_for_scene; @@ -182,7 +182,9 @@ Ref Resource::duplicate_for_local_scene(Node *p_for_scene, Mapset(E->get().name, p); } - return Ref(r); + RES res = Ref(r); + + return res; } void Resource::configure_for_local_scene(Node *p_for_scene, Map, Ref > &remap_cache) { diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 31ee31745aa..66a9c5babda 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -314,6 +314,11 @@ AnimationNodeOneShot::AnimationNodeOneShot() { mix = MIX_MODE_BLEND; sync = false; + + active = "active"; + prev_active = "prev_active"; + time = "time"; + remaining = "remaining"; } //////////////////////////////////////////////// diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 143a1438ea0..d6c22d5664d 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -34,7 +34,7 @@ void Material::set_next_pass(const Ref &p_pass) { - ERR_FAIL_COND(p_pass == this); + ERR_FAIL_COND(p_pass.ptr() == this); if (next_pass == p_pass) return;