### 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
if (!_refresh_device_info()) {
		OS::get_singleton()->alert("Your system does not support XInput 2.\n"
								   "Please upgrade your distribution.",
				"Unable to initialize XInput");
		r_error = ERR_UNAVAILABLE;
		return;
	}
	xim = XOpenIM(x11_display, nullptr, nullptr, nullptr);
	if (xim == nullptr) {
		WARN_PRINT("XOpenIM failed");
		xim_style = 0L;
	} else {
		::XIMCallback im_destroy_callback;
		im_destroy_callback.client_data = (::XPointer)(this);
		im_destroy_callback.callback = (::XIMProc)(_xim_destroy_callback);
		if (XSetIMValues(xim, XNDestroyCallback, &im_destroy_callback,
					nullptr) != nullptr) {
			WARN_PRINT("Error setting XIM destroy callback");
		}
		::XIMStyles *xim_styles = nullptr;
		xim_style = 0L;
		char *imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, nullptr);
		if (imvalret != nullptr || xim_styles == nullptr) {
			fprintf(stderr, "Input method doesn't support any styles\n");
		}
		if (xim_styles) {
			xim_style = 0L;
			for (int i = 0; i < xim_styles->count_styles; i++) {
				const ::XIMStyle &style = xim_styles->supported_styles[i];
				if (!_is_xim_style_supported(style)) {