Browse Source

Crash fixes for material and animtree

Juan Linietsky 7 years ago
parent
commit
031f763d4f
5 changed files with 23 additions and 8 deletions
  1. 11 5
      core/object.cpp
  2. 2 0
      core/object.h
  3. 4 2
      core/resource.cpp
  4. 5 0
      scene/animation/animation_blend_tree.cpp
  5. 1 1
      scene/resources/material.cpp

+ 11 - 5
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) {
 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);
 	ERR_FAIL_NULL(p_to_object);
 	Signal *s = signal_map.getptr(p_signal);
 	Signal *s = signal_map.getptr(p_signal);
 	if (!s) {
 	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];
 	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);
 	p_to_object->connections.erase(slot->cE);
@@ -1965,13 +1971,13 @@ Object::~Object() {
 		Connection &c = E->get();
 		Connection &c = E->get();
 		ERR_CONTINUE(c.source != this); //bug?
 		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()) {
 	while (connections.size()) {
 
 
 		Connection c = connections.front()->get();
 		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);
 	ObjectDB::remove_instance(this);

+ 2 - 0
core/object.h

@@ -551,6 +551,8 @@ protected:
 	friend class ClassDB;
 	friend class ClassDB;
 	virtual void _validate_property(PropertyInfo &property) const;
 	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++
 public: //should be protected, but bug in clang++
 	static void initialize_class();
 	static void initialize_class();
 	_FORCE_INLINE_ static void register_custom_data_to_otdb(){};
 	_FORCE_INLINE_ static void register_custom_data_to_otdb(){};

+ 4 - 2
core/resource.cpp

@@ -151,7 +151,7 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res
 	List<PropertyInfo> plist;
 	List<PropertyInfo> plist;
 	get_property_list(&plist);
 	get_property_list(&plist);
 
 
-	Resource *r = (Resource *)ClassDB::instance(get_class());
+	Resource *r = Object::cast_to<Resource>(ClassDB::instance(get_class()));
 	ERR_FAIL_COND_V(!r, Ref<Resource>());
 	ERR_FAIL_COND_V(!r, Ref<Resource>());
 
 
 	r->local_scene = p_for_scene;
 	r->local_scene = p_for_scene;
@@ -182,7 +182,9 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res
 		r->set(E->get().name, p);
 		r->set(E->get().name, p);
 	}
 	}
 
 
-	return Ref<Resource>(r);
+	RES res = Ref<Resource>(r);
+
+	return res;
 }
 }
 
 
 void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) {
 void Resource::configure_for_local_scene(Node *p_for_scene, Map<Ref<Resource>, Ref<Resource> > &remap_cache) {

+ 5 - 0
scene/animation/animation_blend_tree.cpp

@@ -314,6 +314,11 @@ AnimationNodeOneShot::AnimationNodeOneShot() {
 
 
 	mix = MIX_MODE_BLEND;
 	mix = MIX_MODE_BLEND;
 	sync = false;
 	sync = false;
+
+	active = "active";
+	prev_active = "prev_active";
+	time = "time";
+	remaining = "remaining";
 }
 }
 
 
 ////////////////////////////////////////////////
 ////////////////////////////////////////////////

+ 1 - 1
scene/resources/material.cpp

@@ -34,7 +34,7 @@
 
 
 void Material::set_next_pass(const Ref<Material> &p_pass) {
 void Material::set_next_pass(const Ref<Material> &p_pass) {
 
 
-	ERR_FAIL_COND(p_pass == this);
+	ERR_FAIL_COND(p_pass.ptr() == this);
 
 
 	if (next_pass == p_pass)
 	if (next_pass == p_pass)
 		return;
 		return;