### Godot version

2992ffd25523cb8b3e0ef1b873c40115b8940178

### System information

Windows 10

### Issue description

Godot crashes randomly within a few seconds after project start when moving with the mouse.

![win_err](https://github.com/godotengine/godot/assets/52464204/1da28596-d95b-40f3-b32f-12219ec02c5d)

Started after recent merge of https://github.com/godotengine/godot/pull/67791.
I can confirm that reverting the pr fixes the crashes.

### Steps to reproduce

see desc

### Minimal reproduction project

N/A
}
		} else {
			ERR_FAIL_V_MSG(Ref<Image>(), "Invalid screen index: " + itos(p_screen) + "(count: " + itos(xin_count) + ").");
		}
	} else {
		int x_count = XScreenCount(x11_display);
		if (p_screen < x_count) {
			Window root = XRootWindow(x11_display, p_screen);
			XWindowAttributes root_attrs;
			XGetWindowAttributes(x11_display, root, &root_attrs);
			image = XGetImage(x11_display, root, root_attrs.x, root_attrs.y, root_attrs.width, root_attrs.height, AllPlanes, ZPixmap);
		} else {
			ERR_FAIL_V_MSG(Ref<Image>(), "Invalid screen index: " + itos(p_screen) + "(count: " + itos(x_count) + ").");
		}
	}
	Ref<Image> img;
	if (image) {
		int width = image->width;
		int height = image->height;
		Vector<uint8_t> img_data;
		img_data.resize(height * width * 4);
		uint8_t *sr = (uint8_t *)image->data;
		uint8_t *wr = (uint8_t *)img_data.ptrw();
		if (image->bits_per_pixel == 24 && image->red_mask == 0xff0000 && image->green_mask == 0x00ff00 && image->blue_mask == 0x0000ff) {
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					wr[(y * width + x) * 4 + 0] = sr[(y * width + x) * 3 + 2];
					wr[(y * width + x) * 4 + 1] = sr[(y * width + x) * 3 + 1];
					wr[(y * width + x) * 4 + 2] = sr[(y * width + x) * 3 + 0];
					wr[(y * width + x) * 4 + 3] = 255;