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

#ifndef _3D_DISABLED
	Vector2 last_pos(1e20, 1e20);
	CollisionObject3D *last_object = nullptr;
	ObjectID last_id;
	PhysicsDirectSpaceState3D::RayResult result;
#endif 
	PhysicsDirectSpaceState2D *ss2d = PhysicsServer2D::get_singleton()->space_get_direct_state(find_world_2d()->get_space());
	SubViewportContainer *parent_svc = Object::cast_to<SubViewportContainer>(get_parent());
	bool parent_ignore_mouse = (parent_svc && parent_svc->get_mouse_filter() == Control::MOUSE_FILTER_IGNORE);
	bool create_passive_hover_event = true;
	if (gui.mouse_over || parent_ignore_mouse) {
		
		
		create_passive_hover_event = false;
	} else {
		for (const Ref<InputEvent> &e : physics_picking_events) {
			Ref<InputEventMouse> m = e;
			if (m.is_valid()) {
				
				create_passive_hover_event = false;
				break;
			}
		}
	}
	if (create_passive_hover_event) {
		
		
		
		Ref<InputEventMouseMotion> mm;
		mm.instantiate();