### 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.
Rect2 swrect = Rect2i(sw->get_position(), sw->get_size());
					if (!sw->get_flag(Window::FLAG_BORDERLESS)) {
						int title_height = sw->get_theme_constant(SNAME("title_height"));
						swrect.position.y -= title_height;
						swrect.size.y += title_height;
					}
					if (swrect.has_point(viewport_pos)) {
						viewport_under = sw;
						viewport_pos -= sw->get_position();
					}
				}
				if (!viewport_under) {
					
					viewport_under = embedder;
				}
			} else {
				
				Vector2i screen_mouse_pos = DisplayServer::get_singleton()->mouse_get_position();
				DisplayServer::WindowID window_id = DisplayServer::get_singleton()->get_window_at_screen_position(screen_mouse_pos);
				if (window_id != DisplayServer::INVALID_WINDOW_ID) {
					ObjectID object_under = DisplayServer::get_singleton()->window_get_attached_instance_id(window_id);
					if (object_under != ObjectID()) { 
						Window *w = Object::cast_to<Window>(ObjectDB::get_instance(object_under));
						if (w) {
							viewport_under = w;
							viewport_pos = screen_mouse_pos - w->get_position();
						}
					}
				}
			}