### 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.
ERR_FAIL_NULL(p_control);
	ERR_FAIL_COND(p_control->is_inside_tree());
	ERR_FAIL_COND(p_control->get_parent() != nullptr);
	Control *drag_preview = _gui_get_drag_preview();
	if (drag_preview) {
		memdelete(drag_preview);
	}
	p_control->set_as_top_level(true);
	p_control->set_position(gui.last_mouse_pos);
	p_base->get_root_parent_control()->add_child(p_control); 
	p_control->move_to_front();
	gui.drag_preview_id = p_control->get_instance_id();
}
Control *Viewport::_gui_get_drag_preview() {
	if (gui.drag_preview_id.is_null()) {
		return nullptr;
	} else {
		Control *drag_preview = Object::cast_to<Control>(ObjectDB::get_instance(gui.drag_preview_id));
		if (!drag_preview) {
			ERR_PRINT("Don't free the control set as drag preview.");
			gui.drag_preview_id = ObjectID();
		}
		return drag_preview;
	}
}
void Viewport::_gui_remove_root_control(List<Control *>::Element *RI) {