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

}
		Control *over = nullptr;
		if (gui.mouse_focus) {
			over = gui.mouse_focus;
		} else if (gui.mouse_in_viewport) {
			over = gui_find_control(mpos);
		}
		DisplayServer::CursorShape ds_cursor_shape = (DisplayServer::CursorShape)Input::get_singleton()->get_default_cursor_shape();
		if (over) {
			Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse();
			Size2 pos = localizer.xform(mpos);
			Vector2 velocity = localizer.basis_xform(mm->get_velocity());
			Vector2 rel = localizer.basis_xform(mm->get_relative());
			mm = mm->xformed_by(Transform2D()); 
			mm->set_global_position(mpos);
			mm->set_velocity(velocity);
			mm->set_relative(rel);
			if (mm->get_button_mask().is_empty()) {
				
				bool is_tooltip_shown = false;
				if (gui.tooltip_popup) {
					if (gui.tooltip_control) {
						String tooltip = _gui_get_tooltip(over, gui.tooltip_control->get_global_transform().xform_inv(mpos));
						tooltip = tooltip.strip_edges();
						if (tooltip.length() == 0) {
							_gui_cancel_tooltip();
						} else if (gui.tooltip_label) {
							if (tooltip == gui.tooltip_label->get_text()) {
								is_tooltip_shown = true;
							}