### Godot version

v4.0 rc6

### System information

Windows 10

### Issue description

When using a ViewportTexture from a SubViewport on a TextureRect, it throws errors after running the scene once and then switching scenes in the editor.
![Pasted image 20230227212626](https://user-images.githubusercontent.com/44676282/221680047-984fa03e-33d1-4856-9a7f-1700b28423cf.png)


### Steps to reproduce

Run the canvas-scene once.
Switch to another scene in the editor.
Switch back to the canvas-scene

### Minimal reproduction project

[ViewportTextureError.zip](https://github.com/godotengine/godot/files/10844099/ViewportTextureError.zip)

if (is_embedding_subwindows()) {
		for (int i = gui.sub_windows.size() - 1; i >= 0; i--) {
			Window *sw = gui.sub_windows[i].window;
			Rect2 swrect = Rect2(sw->get_position(), sw->get_size());
			Rect2 swrect_border = swrect;
			if (!sw->get_flag(Window::FLAG_BORDERLESS)) {
				int title_height = sw->get_theme_constant(SNAME("title_height"));
				int margin = sw->get_theme_constant(SNAME("resize_margin"));
				swrect_border.position.y -= title_height + margin;
				swrect_border.size.y += title_height + margin * 2;
				swrect_border.position.x -= margin;
				swrect_border.size.x += margin * 2;
			}
			if (swrect_border.has_point(p_pos)) {
				if (gui.mouse_over) {
					_drop_mouse_over();
				} else if (!gui.subwindow_over) {
					_drop_physics_mouseover();
				}
				if (swrect.has_point(p_pos)) {
					if (sw != gui.subwindow_over) {
						if (gui.subwindow_over) {
							gui.subwindow_over->_mouse_leave_viewport();
						}