summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/node.cpp31
-rw-r--r--scene/main/viewport.cpp15
2 files changed, 36 insertions, 10 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 3242068bf7..ae2ab2af80 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -157,7 +157,7 @@ void Node::_notification(int p_notification) {
// kill children as cleanly as possible
while (data.children.size()) {
- Node *child = data.children[0];
+ Node *child = data.children[data.children.size() - 1]; //begin from the end because its faster and more consistent with creation
remove_child(child);
memdelete(child);
}
@@ -1182,13 +1182,24 @@ void Node::remove_child(Node *p_child) {
ERR_FAIL_COND(data.blocked > 0);
}
+ int child_count = data.children.size();
+ Node **children = data.children.ptrw();
int idx = -1;
- for (int i = 0; i < data.children.size(); i++) {
- if (data.children[i] == p_child) {
+ if (p_child->data.pos >= 0 && p_child->data.pos < child_count) {
+ if (children[p_child->data.pos] == p_child) {
+ idx = p_child->data.pos;
+ }
+ }
+
+ if (idx == -1) { //maybe removed while unparenting or something and index was not updated, so just in case the above fails, try this.
+ for (int i = 0; i < child_count; i++) {
- idx = i;
- break;
+ if (children[i] == p_child) {
+
+ idx = i;
+ break;
+ }
}
}
@@ -1205,10 +1216,14 @@ void Node::remove_child(Node *p_child) {
data.children.remove(idx);
- for (int i = idx; i < data.children.size(); i++) {
+ //update pointer and size
+ child_count = data.children.size();
+ children = data.children.ptrw();
- data.children[i]->data.pos = i;
- data.children[i]->notification(NOTIFICATION_MOVED_IN_PARENT);
+ for (int i = idx; i < child_count; i++) {
+
+ children[i]->data.pos = i;
+ children[i]->notification(NOTIFICATION_MOVED_IN_PARENT);
}
p_child->data.parent = NULL;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 82645aa17a..8545efb966 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1510,12 +1510,17 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
Control *control = Object::cast_to<Control>(ci);
if (control) {
- control->emit_signal(SceneStringNames::get_singleton()->gui_input, ev); //signal should be first, so it's possible to override an event (and then accept it)
+ if (control->data.mouse_filter != Control::MOUSE_FILTER_IGNORE) {
+ control->emit_signal(SceneStringNames::get_singleton()->gui_input, ev); //signal should be first, so it's possible to override an event (and then accept it)
+ }
if (gui.key_event_accepted)
break;
if (!control->is_inside_tree())
break;
- control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev);
+
+ if (control->data.mouse_filter != Control::MOUSE_FILTER_IGNORE) {
+ control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev);
+ }
if (!control->is_inside_tree() || control->is_set_as_toplevel())
break;
@@ -1895,7 +1900,13 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (gui.drag_data.get_type() != Variant::NIL) {
gui.mouse_focus = NULL;
+ break;
} else {
+ if (gui.drag_preview != NULL) {
+ ERR_PRINT("Don't set a drag preview and return null data. Preview was deleted and drag request ignored.");
+ memdelete(gui.drag_preview);
+ gui.drag_preview = NULL;
+ }
gui.dragging = false;
}