Browse Source

Don't obtain a reference to a subwindow

Fixes the wrong location being accessed after changing the order of embedded windows.
This commit also removes an unused variable.
TechnoPorg 3 years ago
parent
commit
acb90ed020
2 changed files with 2 additions and 5 deletions
  1. 1 3
      scene/main/viewport.cpp
  2. 1 2
      scene/main/viewport.h

+ 1 - 3
scene/main/viewport.cpp

@@ -370,8 +370,6 @@ void Viewport::_sub_window_remove(Window *p_window) {
 void Viewport::_notification(int p_what) {
 void Viewport::_notification(int p_what) {
 	switch (p_what) {
 	switch (p_what) {
 		case NOTIFICATION_ENTER_TREE: {
 		case NOTIFICATION_ENTER_TREE: {
-			gui.embedding_subwindows = gui.embed_subwindows_hint;
-
 			if (get_parent()) {
 			if (get_parent()) {
 				parent = get_parent()->get_viewport();
 				parent = get_parent()->get_viewport();
 				RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid());
 				RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid());
@@ -2540,7 +2538,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) {
 	if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
 	if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
 		bool click_on_window = false;
 		bool click_on_window = false;
 		for (int i = gui.sub_windows.size() - 1; i >= 0; i--) {
 		for (int i = gui.sub_windows.size() - 1; i >= 0; i--) {
-			SubWindow &sw = gui.sub_windows.write[i];
+			SubWindow sw = gui.sub_windows.write[i];
 
 
 			// Clicked inside window?
 			// Clicked inside window?
 
 

+ 1 - 2
scene/main/viewport.h

@@ -349,7 +349,6 @@ private:
 		int canvas_sort_index = 0; //for sorting items with canvas as root
 		int canvas_sort_index = 0; //for sorting items with canvas as root
 		bool dragging = false;
 		bool dragging = false;
 		bool embed_subwindows_hint = false;
 		bool embed_subwindows_hint = false;
-		bool embedding_subwindows = false;
 
 
 		Window *subwindow_focused = nullptr;
 		Window *subwindow_focused = nullptr;
 		SubWindowDrag subwindow_drag = SUB_WINDOW_DRAG_DISABLED;
 		SubWindowDrag subwindow_drag = SUB_WINDOW_DRAG_DISABLED;
@@ -360,7 +359,7 @@ private:
 		SubWindowResize subwindow_resize_mode;
 		SubWindowResize subwindow_resize_mode;
 		Rect2i subwindow_resize_from_rect;
 		Rect2i subwindow_resize_from_rect;
 
 
-		Vector<SubWindow> sub_windows;
+		Vector<SubWindow> sub_windows; // Don't obtain references or pointers to the elements, as their location can change.
 	} gui;
 	} gui;
 
 
 	DefaultCanvasItemTextureFilter default_canvas_item_texture_filter = DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR;
 	DefaultCanvasItemTextureFilter default_canvas_item_texture_filter = DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR;