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

}
		}
#endif 
	}
}
RID Viewport::get_viewport_rid() const {
	ERR_READ_THREAD_GUARD_V(RID());
	return viewport;
}
void Viewport::update_canvas_items() {
	ERR_MAIN_THREAD_GUARD;
	if (!is_inside_tree()) {
		return;
	}
	_update_canvas_items(this);
}
void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, bool p_allocated) {
	Transform2D stretch_transform_new = Transform2D();
	if (is_size_2d_override_stretch_enabled() && p_size_2d_override.width > 0 && p_size_2d_override.height > 0) {
		Size2 scale = Size2(p_size) / Size2(p_size_2d_override);
		stretch_transform_new.scale(scale);
	}
	Size2i new_size = p_size.max(Size2i(2, 2));
	if (size == new_size && size_allocated == p_allocated && stretch_transform == stretch_transform_new && p_size_2d_override == size_2d_override) {
		return;
	}
	size = new_size;
	size_allocated = p_allocated;
	size_2d_override = p_size_2d_override;
	stretch_transform = stretch_transform_new;