Browse Source

Merge pull request #49553 from timothyqiu/viewport-outside-tree

Fix Viewport crashes when not in tree
Rémi Verschelde 4 years ago
parent
commit
1003054134
1 changed files with 3 additions and 0 deletions
  1. 3 0
      scene/main/viewport.cpp

+ 3 - 0
scene/main/viewport.cpp

@@ -2547,6 +2547,8 @@ void Viewport::_gui_remove_control(Control *p_control) {
 }
 }
 
 
 Window *Viewport::get_base_window() const {
 Window *Viewport::get_base_window() const {
+	ERR_FAIL_COND_V(!is_inside_tree(), nullptr);
+
 	Viewport *v = const_cast<Viewport *>(this);
 	Viewport *v = const_cast<Viewport *>(this);
 	Window *w = Object::cast_to<Window>(v);
 	Window *w = Object::cast_to<Window>(v);
 	while (!w) {
 	while (!w) {
@@ -3336,6 +3338,7 @@ bool Viewport::is_input_handled() const {
 		return local_input_handled;
 		return local_input_handled;
 	} else {
 	} else {
 		const Viewport *vp = this;
 		const Viewport *vp = this;
+		ERR_FAIL_COND_V(!is_inside_tree(), false);
 		while (true) {
 		while (true) {
 			if (Object::cast_to<Window>(vp)) {
 			if (Object::cast_to<Window>(vp)) {
 				break;
 				break;