### 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)

ERR_MAIN_THREAD_GUARD_V(nullptr);
	
	_gui_sort_roots();
	for (List<Control *>::Element *E = gui.roots.back(); E; E = E->prev()) {
		Control *sw = E->get();
		if (!sw->is_visible_in_tree()) {
			continue;
		}
		Transform2D xform;
		CanvasItem *pci = sw->get_parent_item();
		if (pci) {
			xform = pci->get_global_transform_with_canvas();
		} else {
			xform = sw->get_canvas_transform();
		}
		Control *ret = _gui_find_control_at_pos(sw, p_global, xform);
		if (ret) {
			return ret;
		}
	}
	return nullptr;
}
Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform) {