### 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_THREAD_GUARD;
	gui.embed_subwindows_hint = p_embed;
}
bool Viewport::is_embedding_subwindows() const {
	ERR_READ_THREAD_GUARD_V(false);
	return gui.embed_subwindows_hint;
}
TypedArray<Window> Viewport::get_embedded_subwindows() const {
	TypedArray<Window> windows;
	for (int i = 0; i < gui.sub_windows.size(); i++) {
		windows.append(gui.sub_windows[i].window);
	}
	return windows;
}
void Viewport::subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect) {
	int index = _sub_window_find(p_window);
	ERR_FAIL_COND(index == -1);
	gui.sub_windows.write[index].parent_safe_rect = p_rect;
}
Rect2i Viewport::subwindow_get_popup_safe_rect(Window *p_window) const {
	int index = _sub_window_find(p_window);
	
	
	if (index == -1) {
		return Rect2i();
	}
	
	return gui.sub_windows[index].parent_safe_rect;
}
void Viewport::pass_mouse_focus_to(Viewport *p_viewport, Control *p_control) {