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

if (audio_listener_2d == p_listener) {
		audio_listener_2d = nullptr;
	}
}
void Viewport::_canvas_layer_add(CanvasLayer *p_canvas_layer) {
	canvas_layers.insert(p_canvas_layer);
}
void Viewport::_canvas_layer_remove(CanvasLayer *p_canvas_layer) {
	canvas_layers.erase(p_canvas_layer);
}
void Viewport::set_transparent_background(bool p_enable) {
	ERR_MAIN_THREAD_GUARD;
	transparent_bg = p_enable;
	RS::get_singleton()->viewport_set_transparent_background(viewport, p_enable);
}
bool Viewport::has_transparent_background() const {
	ERR_READ_THREAD_GUARD_V(false);
	return transparent_bg;
}
void Viewport::set_use_hdr_2d(bool p_enable) {
	ERR_MAIN_THREAD_GUARD;
	use_hdr_2d = p_enable;
	RS::get_singleton()->viewport_set_use_hdr_2d(viewport, p_enable);
}
bool Viewport::is_using_hdr_2d() const {
	ERR_READ_THREAD_GUARD_V(false);
	return use_hdr_2d;
}
void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) {