### 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_
	return gravity;
}
Vector3 Input::get_accelerometer() const {
	_THREAD_SAFE_METHOD_
	return accelerometer;
}
Vector3 Input::get_magnetometer() const {
	_THREAD_SAFE_METHOD_
	return magnetometer;
}
Vector3 Input::get_gyroscope() const {
	_THREAD_SAFE_METHOD_
	return gyroscope;
}
void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated) {
	
	
	DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
	
	
	
	
	
	
	Ref<InputEventKey> k = p_event;
	if (k.is_valid() && !k->is_echo() && k->get_keycode() != Key::NONE) {
		if (k->is_pressed()) {