### Godot version

4.0.3-stable

### System information

Windows 10

### Issue description

In some projects ViewportTexture remains pink and doesn't render viewport content after upgrading from 4.0.2-stable to 4.0.3-stable. If a pair of files viewport.h/viewport.cpp are downgraded back to what they were in 4.0.2-stable, problem goes away.

This is how it looks in 4.0.3-stable:
![4 0 3_stable_viewport_4 0 3](https://github.com/godotengine/godot/assets/1449921/44c191a9-4b67-4b02-90b6-4ab615f62a73)

And this is how it looks if viewport.h/viewport.cpp are downgraded back to what they were in 4.0.2-stable.
![4 0 3_stable_viewport_4 0 2](https://github.com/godotengine/godot/assets/1449921/f5abc605-f129-4222-9c0e-e9a07621dd9d)



### Steps to reproduce

Unfortunately, I cannot come up wit a simple demo project reproducing the problem. It exists in some projects and doesn't exist in others.


### Minimal reproduction project

Cannot produce a simple project reproducing the problem. In simple projects it works fine.
if (!has_mouse_event) {
		
		
		
		Ref<InputEventMouseMotion> mm;
		mm.instantiate();
		mm->set_device(InputEvent::DEVICE_ID_INTERNAL);
		mm->set_position(get_mouse_position());
		mm->set_global_position(mm->get_position());
		mm->set_alt_pressed(Input::get_singleton()->is_key_pressed(Key::ALT));
		mm->set_shift_pressed(Input::get_singleton()->is_key_pressed(Key::SHIFT));
		mm->set_ctrl_pressed(Input::get_singleton()->is_key_pressed(Key::CTRL));
		mm->set_meta_pressed(Input::get_singleton()->is_key_pressed(Key::META));
		mm->set_button_mask(Input::get_singleton()->get_mouse_button_mask());
		physics_picking_events.push_back(mm);
	}
	while (physics_picking_events.size()) {
		Ref<InputEvent> ev = physics_picking_events.front()->get();
		physics_picking_events.pop_front();
		Vector2 pos;
		bool is_mouse = false;
		Ref<InputEventMouseMotion> mm = ev;
		if (mm.is_valid()) {
			pos = mm->get_position();
			is_mouse = true;
		}
		Ref<InputEventMouseButton> mb = ev;
		if (mb.is_valid()) {
			pos = mb->get_position();
			is_mouse = true;