### 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 (int i = 0; i < JOYPADS_MAX; i++) {
		if (!joy_names.has(i) || !joy_names[i].connected) {
			return i;
		}
	}
	return -1;
}
Input::Input() {
	singleton = this;
	
	{
		int i = 0;
		while (DefaultControllerMappings::mappings[i]) {
			parse_mapping(DefaultControllerMappings::mappings[i++]);
		}
	}
	
	String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG");
	if (!env_mapping.is_empty()) {
		Vector<String> entries = env_mapping.split("\n");
		for (int i = 0; i < entries.size(); i++) {
			if (entries[i].is_empty()) {
				continue;
			}