Pad: Fix crash on shutdown in macOS

This commit is contained in:
TellowKrinkle 2021-08-14 21:42:40 -05:00 committed by tellowkrinkle
parent d96b1ef525
commit 7af74deaac
6 changed files with 19 additions and 30 deletions

View File

@ -30,13 +30,13 @@ void Device::DoRumble(unsigned type, unsigned pad)
{
int index = uid_to_index(pad);
if (index >= 0)
device_manager->devices[index]->Rumble(type, pad);
device_manager.devices[index]->Rumble(type, pad);
}
size_t Device::index_to_uid(int index)
{
if ((index >= 0) && (index < (int)device_manager->devices.size()))
return device_manager->devices[index]->GetUniqueIdentifier();
if ((index >= 0) && (index < (int)device_manager.devices.size()))
return device_manager.devices[index]->GetUniqueIdentifier();
else
return 0;
}
@ -45,16 +45,16 @@ int Device::uid_to_index(int pad)
{
size_t uid = g_conf.get_joy_uid(pad);
for (int i = 0; i < (int)device_manager->devices.size(); ++i)
for (int i = 0; i < (int)device_manager.devices.size(); ++i)
{
if (device_manager->devices[i]->GetUniqueIdentifier() == uid)
if (device_manager.devices[i]->GetUniqueIdentifier() == uid)
return i;
}
// Current uid wasn't found maybe the pad was unplugged. Or
// user didn't select it. Fallback to 1st pad for
// 1st player. And 2nd pad for 2nd player.
if ((int)device_manager->devices.size() > pad)
if ((int)device_manager.devices.size() > pad)
return pad;
return -1;

View File

@ -22,16 +22,7 @@
#include "SDL/joystick.h"
#endif
std::unique_ptr<InputDeviceManager> device_manager(new InputDeviceManager);
InputDeviceManager::InputDeviceManager()
{
}
InputDeviceManager::~InputDeviceManager()
{
device_manager->devices.clear();
}
InputDeviceManager device_manager;
// Needs to be moved to individual device code, as does the keyboard input.
void PollForJoystickInput(int cpad)
@ -40,7 +31,7 @@ void PollForJoystickInput(int cpad)
if (index < 0)
return;
auto& gamePad = device_manager->devices[index];
auto& gamePad = device_manager.devices[index];
gamePad->UpdateDeviceState();
@ -83,6 +74,6 @@ void InputDeviceManager::Update()
void EnumerateDevices()
{
#ifdef SDL_BUILD
JoystickInfo::EnumerateJoysticks(device_manager->devices);
JoystickInfo::EnumerateJoysticks(device_manager.devices);
#endif
}

View File

@ -23,14 +23,12 @@ class Device;
class InputDeviceManager
{
public:
InputDeviceManager();
~InputDeviceManager();
void Update();
std::vector<std::unique_ptr<Device>> devices;
};
extern std::unique_ptr<InputDeviceManager> device_manager;
extern InputDeviceManager device_manager;
/*
* Find every interesting device and create right structure for them(depends on backend)

View File

@ -54,7 +54,7 @@ s32 _PADopen(void* pDsp)
void _PADclose()
{
device_manager->devices.clear();
device_manager.devices.clear();
}
void PADupdate(int pad)
@ -74,7 +74,7 @@ void PADupdate(int pad)
// Actually PADupdate is always call with pad == 0. So you need to update both
// pads -- Gregory
device_manager->Update();
device_manager.Update();
}
void PADconfigure()

View File

@ -24,7 +24,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow* parent)
wxBoxSizer* gamepad_box = new wxBoxSizer(wxVERTICAL);
wxArrayString choices;
for (const auto& j : device_manager->devices)
for (const auto& j : device_manager.devices)
{
choices.Add(j->GetName());
}
@ -72,7 +72,7 @@ void GamepadConfiguration::InitGamepadConfiguration()
* if the pad id is 1, you need at least 2 gamepads connected,
* Prevent to use a non-initialized value (core dump)
*/
if (device_manager->devices.size() >= m_pad_id + 1)
if (device_manager.devices.size() >= m_pad_id + 1)
{
/*
* Determine if the device can use rumble
@ -81,7 +81,7 @@ void GamepadConfiguration::InitGamepadConfiguration()
*/
// Bad idea. Some connected devices might support rumble but not all connected devices.
// if (!device_manager->devices[m_pad_id]->TestForce(0.001f)) {
// if (!device_manager.devices[m_pad_id]->TestForce(0.001f)) {
// wxMessageBox(L"Rumble is not available for your device.");
// m_cb_rumble->Disable(); // disable the rumble checkbox
// m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
@ -114,7 +114,7 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent& event)
// convert in a float value between 0 and 1, and run rumble feedback.
// 0 to 1 scales to 0x0 to 0x7FFF
device_manager->devices[m_pad_id]->TestForce(m_sl_rumble_intensity->GetValue() / (float)0x7FFF);
device_manager.devices[m_pad_id]->TestForce(m_sl_rumble_intensity->GetValue() / (float)0x7FFF);
}
else if (sl_id == joy_slider_id)
{
@ -135,7 +135,7 @@ void GamepadConfiguration::OnCheckboxChange(wxCommandEvent& event)
g_conf.pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
if (m_cb_rumble->GetValue())
{
device_manager->devices[m_pad_id]->TestForce();
device_manager.devices[m_pad_id]->TestForce();
m_sl_rumble_intensity->Enable();
}
else

View File

@ -64,9 +64,9 @@ void JoystickConfiguration::InitJoystickConfiguration()
* if the pad id is 1, you need at least 2 gamepads connected,
* Prevent using a non-initialized value (core dump)
*/
if (device_manager->devices.size() < m_pad_id + 1)
if (device_manager.devices.size() < m_pad_id + 1)
{
if (device_manager->devices.empty())
if (device_manager.devices.empty())
wxMessageBox(L"No gamepad detected.");
else
wxMessageBox(L"No second gamepad detected.");