### 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
_THREAD_SAFE_METHOD_
	WindowData &wd = windows[MAIN_WINDOW_ID];
	int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&set_icon_errorhandler);
	Atom net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
	if (p_icon.is_valid()) {
		ERR_FAIL_COND(p_icon->get_width() <= 0 || p_icon->get_height() <= 0);
		Ref<Image> img = p_icon->duplicate();
		img->convert(Image::FORMAT_RGBA8);
		while (true) {
			int w = img->get_width();
			int h = img->get_height();
			if (g_set_icon_error) {
				g_set_icon_error = false;
				WARN_PRINT("Icon too large, attempting to resize icon.");
				int new_width, new_height;
				if (w > h) {
					new_width = w / 2;
					new_height = h * new_width / w;
				} else {
					new_height = h / 2;
					new_width = w * new_height / h;
				}
				w = new_width;
				h = new_height;
				if (!w || !h) {
					WARN_PRINT("Unable to set icon.");
					break;
				}
				img->resize(w, h, Image::INTERPOLATE_CUBIC);