### Godot version

v3.5.stable.official [991bb6ac7]

### System information

Debian 11 - Intel Ivybridge Mobile - GLES3

### Issue description

Pretty much what the title says, the engine freezes when I call Sprite.new() from a method that I previously connected to `joy_connection_changed` signal. No errors are shown.

### Steps to reproduce

1. Run the minimal reproduction project, you will see the Godot icon moving around.
2. Connect or disconnect a gamepad and you will see the icon stops moving due to engine freeze.

### Minimal reproduction project

[minimal-reproduction-project.zip](https://github.com/godotengine/godot/files/11821885/minimal-reproduction-project.zip)

_THREAD_SAFE_METHOD_;
	ERR_FAIL_INDEX((int)p_axis, (int)JoyAxis::MAX);
	Joypad &joy = joy_names[p_device];
	if (joy.last_axis[(size_t)p_axis] == p_value) {
		return;
	}
	joy.last_axis[(size_t)p_axis] = p_value;
	if (joy.mapping == -1) {
		_axis_event(p_device, p_axis, p_value);
		return;
	}
	JoyEvent map = _get_mapped_axis_event(map_db[joy.mapping], p_axis, p_value);
	if (map.type == TYPE_BUTTON) {
		bool pressed = map.value > 0.5;
		if (pressed != joy_buttons_pressed.has(_combine_device((JoyButton)map.index, p_device))) {
			_button_event(p_device, (JoyButton)map.index, pressed);
		}
		
		switch ((JoyButton)map.index) {
			case JoyButton::DPAD_UP:
				if (joy_buttons_pressed.has(_combine_device(JoyButton::DPAD_DOWN, p_device))) {
					_button_event(p_device, JoyButton::DPAD_DOWN, false);
				}
				break;
			case JoyButton::DPAD_DOWN:
				if (joy_buttons_pressed.has(_combine_device(JoyButton::DPAD_UP, p_device))) {
					_button_event(p_device, JoyButton::DPAD_UP, false);