### Godot version

4.1 beta 3

The same project works fine on 4.1 **beta 1 and beta 2.**

### System information

Tested on MacOS, Fedora and HTML5

### Issue description

I have a problem in version 4.1 beta 3 with a popup (popup panel). The first time it always displays correctly. Every subsequent time, I only see a black spot. 

[Nagranie ekranu z 2023-06-23 11-35-28.webm](https://github.com/godotengine/godot/assets/5132385/f7a7ad08-754c-4b4b-b594-b6880eff5f3d)

*The same if I show popup by methods like popup_centered.


### Steps to reproduce

I'm trying to reproduce it with a clean and minimal example, but unfortunately, without success. Maybe someone else has this issue or knows a way to reproduce it?

### Minimal reproduction project

I'm trying to create it.
glClear(GL_COLOR_BUFFER_BIT);
	CopyEffects::get_singleton()->copy_to_rect(Rect2i(0, 0, 1.0, 1.0));
	glReadPixels(0, 0, texture->alloc_width, texture->alloc_height, GL_RGBA, GL_UNSIGNED_BYTE, &w[0]);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glDeleteTextures(1, &temp_color_texture);
	glDeleteFramebuffers(1, &temp_framebuffer);
	data.resize(data_size);
	ERR_FAIL_COND_V(data.size() == 0, Ref<Image>());
	Ref<Image> image = Image::create_from_data(texture->width, texture->height, false, Image::FORMAT_RGBA8, data);
	ERR_FAIL_COND_V(image->is_empty(), Ref<Image>());
	if (texture->format != Image::FORMAT_RGBA8) {
		image->convert(texture->format);
	}
	if (texture->mipmaps > 1) {
		image->generate_mipmaps();
	}
#endif
#ifdef TOOLS_ENABLED
	if (Engine::get_singleton()->is_editor_hint() && !texture->is_render_target) {
		texture->image_cache_2d = image;
	}
#endif
	return image;
}
void TextureStorage::texture_replace(RID p_texture, RID p_by_texture) {
	Texture *tex_to = texture_owner.get_or_null(p_texture);
	ERR_FAIL_COND(!tex_to);
	ERR_FAIL_COND(tex_to->is_proxy); 
	Texture *tex_from = texture_owner.get_or_null(p_by_texture);
	ERR_FAIL_COND(!tex_from);