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

return use_input_buffering;
}
void Input::set_use_input_buffering(bool p_enable) {
	use_input_buffering = p_enable;
}
void Input::set_use_accumulated_input(bool p_enable) {
	use_accumulated_input = p_enable;
}
bool Input::is_using_accumulated_input() {
	return use_accumulated_input;
}
void Input::release_pressed_events() {
	flush_buffered_events(); 
	keys_pressed.clear();
	physical_keys_pressed.clear();
	key_label_pressed.clear();
	joy_buttons_pressed.clear();
	_joy_axis.clear();
	for (const KeyValue<StringName, Input::Action> &E : action_state) {
		if (E.value.pressed) {
			action_release(E.key);
		}
	}
}
void Input::set_event_dispatch_function(EventDispatchFunc p_function) {