Browse Source

Fix Node::move_child() crash if moving to the end plus one

(cherry picked from commit 6c1b7fd899f72136a1cc17eb9ae81746d8d98572)
Pedro J. Estébanez 8 years ago
parent
commit
c1630f0e60
1 changed files with 5 additions and 0 deletions
  1. 5 0
      scene/main/node.cpp

+ 5 - 0
scene/main/node.cpp

@@ -274,6 +274,11 @@ void Node::move_child(Node *p_child, int p_pos) {
 		ERR_FAIL_COND(data.blocked > 0);
 	}
 
+	// Specifying one place beyond the end
+	// means the same as moving to the last position
+	if (p_pos == data.children.size())
+		p_pos--;
+
 	data.children.remove(p_child->data.pos);
 	data.children.insert(p_pos, p_child);