### 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_;
	const Joypad &joy = joy_names[p_device];
	JoyEvent map[(size_t)HatDir::MAX];
	map[(size_t)HatDir::UP].type = TYPE_BUTTON;
	map[(size_t)HatDir::UP].index = (int)JoyButton::DPAD_UP;
	map[(size_t)HatDir::UP].value = 0;
	map[(size_t)HatDir::RIGHT].type = TYPE_BUTTON;
	map[(size_t)HatDir::RIGHT].index = (int)JoyButton::DPAD_RIGHT;
	map[(size_t)HatDir::RIGHT].value = 0;
	map[(size_t)HatDir::DOWN].type = TYPE_BUTTON;
	map[(size_t)HatDir::DOWN].index = (int)JoyButton::DPAD_DOWN;
	map[(size_t)HatDir::DOWN].value = 0;
	map[(size_t)HatDir::LEFT].type = TYPE_BUTTON;
	map[(size_t)HatDir::LEFT].index = (int)JoyButton::DPAD_LEFT;
	map[(size_t)HatDir::LEFT].value = 0;
	if (joy.mapping != -1) {
		_get_mapped_hat_events(map_db[joy.mapping], (HatDir)0, map);
	}