### Godot version

Godot 4.0 beta 14

### System information

Debian 11, X11 Nvidia proprietary driver, GLES3 Compatibility

### Issue description

When creating a new scene and add a Sprite2D node, the node image becomes corrupted when selecting the root node.
The problem is gone after saving & re-opening the editor.

![Screenshot from 2023-01-24 12-19-24](https://user-images.githubusercontent.com/94308700/214218462-979ed804-6128-4fbb-87d3-286de9db9e7f.png)

Selecting the root node:
![Screenshot from 2023-01-24 12-19-35](https://user-images.githubusercontent.com/94308700/214218528-944083f4-f5fc-4088-a6c8-7702215ce1a0.png)

The resource preview is wrong too.
![Screenshot from 2023-01-24 12-19-48](https://user-images.githubusercontent.com/94308700/214218557-34177eba-98cc-46aa-86f3-9f613899137a.png)


### Steps to reproduce

Pretty straightforward.

### Minimal reproduction project

Any sprite will do, i think.
ure> &E : texture_atlas.textures) {
			TextureAtlas::SortItem &si = itemsv.write[idx];
			Texture *src_tex = get_texture(E.key);
			si.size.width = (src_tex->width / border) + 1;
			si.size.height = (src_tex->height / border) + 1;
			si.pixel_size = Size2i(src_tex->width, src_tex->height);
			if (base_size < si.size.width) {
				base_size = nearest_power_of_2_templated(si.size.width);
			}
			si.texture = E.key;
			idx++;
		}
		
		itemsv.sort();
		
		int item_count = itemsv.size();
		TextureAtlas::SortItem *items = itemsv.ptrw();
		int atlas_height = 0;
		while (true) {
			Vector<int> v_offsetsv;
			v_offsetsv.resize(base_size);
			int *v_offsets = v_offsetsv.ptrw();
			memset(v_offsets, 0, sizeof(int) * base_size);
			int max_height = 0;
			for (int i = 0; i < item_count; i++) {
				
				TextureAtlas::SortItem &si = items[i];
				int best_idx = -1;
				int best_height = 0x7FFFFFFF;
				for (int j = 0; j <= base_size - si.size.width; j++) {
					int height = 0;
					for (int k = 0; k < si.size.width; k++) {
						int h = v_offsets[k + j];
						if (h > height) {
							height = h;
							if (height > best_height) {
								break; 
							}
						}
					}
					if (height < best_height) {
						best_height = height;
						best_idx = j;
					}
				}
				
				for (int k = 0; k < si.size.width; k++) {
					v_offsets[k + best_idx] = best_height + si.size.height;
				}
				si.pos.x = best_idx;
				si.pos.y = best_height;
				if (si.pos.y + si.size.height > max_height) {
					max_height = si.pos.y + si.size.height;
				}
			}
			if (max_height <= base_size * 2) {
				atlas_height = max_height;
				break; 
			}
			base_size *= 2;
		}
		texture_atlas.size.width = base_size * border;
		texture_atlas.size.height = nearest_power_of_2_templated(atlas_height * border);
		for (int i = 0; i < item_count; i++) {
			TextureAtlas::Texture *t = texture_atlas.textures.getptr(items[i].texture);
			t->uv_rect.position = items[i].pos * border + Vector2i(border / 2, border / 2);
			t->uv_rec