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

List<ObjectID> to_erase;
	for (const KeyValue<ObjectID, uint64_t> &E : physics_2d_mouseover) {
		if (!p_clean_all_frames && E.value == p_frame_reference) {
			continue;
		}
		Object *o = ObjectDB::get_instance(E.key);
		if (o) {
			CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
			if (co && co->is_inside_tree()) {
				if (p_clean_all_frames && p_paused_only && co->can_process()) {
					continue;
				}
				co->_mouse_exit();
			}
		}
		to_erase.push_back(E.key);
	}
	while (to_erase.size()) {
		physics_2d_mouseover.erase(to_erase.front()->get());
		to_erase.pop_front();
	}
	
	List<Pair<ObjectID, int>> shapes_to_erase;
	for (KeyValue<Pair<ObjectID, int>, uint64_t> &E : physics_2d_shape_mouseover) {
		if (!p_clean_all_frames && E.value == p_frame_reference) {
			continue;
		}
		Object *o = ObjectDB::get_instance(E.key.first);
		if (o) {
			CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);