### 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 (gui.key_focus->can_process()) {
				gui.key_focus->_call_gui_input(p_event);
			}
			if (gui.key_event_accepted) {
				set_input_as_handled();
				return;
			}
		}
		Control *from = gui.key_focus ? gui.key_focus : nullptr;
		if (from && p_event->is_pressed()) {
			Control *next = nullptr;
			Ref<InputEventJoypadMotion> joypadmotion_event = p_event;
			if (joypadmotion_event.is_valid()) {
				Input *input = Input::get_singleton();
				if (p_event->is_action_pressed("ui_focus_next") && input->is_action_just_pressed("ui_focus_next")) {
					next = from->find_next_valid_focus();
				}
				if (p_event->is_action_pressed("ui_focus_prev") && input->is_action_just_pressed("ui_focus_prev")) {
					next = from->find_prev_valid_focus();
				}
				if (p_event->is_action_pressed("ui_up") && input->is_action_just_pressed("ui_up")) {
					next = from->_get_focus_neighbor(SIDE_TOP);
				}
				if (p_event->is_action_pressed("ui_left") && input->is_action_just_pressed("ui_left")) {
					next = from->_get_focus_neighbor(SIDE_LEFT);
				}
				if (p_event->is_action_pressed("ui_right") && input->is_action_just_pressed("ui_right")) {
					next = from->_get_focus_neighbor(SIDE_RIGHT);
				}
				if (p_event->is_action_pressed("ui_down") && input->is_action_just_pressed("ui_down")) {