### 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)

}
	for (const KeyValue<StringName, InputMap::Action> &E : InputMap::get_singleton()->get_action_map()) {
		if (InputMap::get_singleton()->event_is_action(p_event, E.key)) {
			Action &action = action_state[E.key];
			
			if (!p_event->is_echo() && is_action_pressed(E.key, false) != p_event->is_action_pressed(E.key)) {
				if (p_event->is_action_pressed(E.key)) {
					action.pressed = true;
					action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
					action.pressed_process_frame = Engine::get_singleton()->get_process_frames();
				} else {
					action.pressed = false;
					action.released_physics_frame = Engine::get_singleton()->get_physics_frames();
					action.released_process_frame = Engine::get_singleton()->get_process_frames();
				}
				action.strength = 0.0f;
				action.raw_strength = 0.0f;
				action.exact = InputMap::get_singleton()->event_is_action(p_event, E.key, true);
			}
			action.strength = p_event->get_action_strength(E.key);
			action.raw_strength = p_event->get_action_raw_strength(E.key);
		}
	}
	if (event_dispatch_function) {
		_THREAD_SAFE_UNLOCK_
		event_dispatch_function(p_event);
		_THREAD_SAFE_LOCK_
	}
}
void Input::set_joy_axis(int p_device, JoyAxis p_axis, float p_value) {