From e2cf1515601fa1c90178e12c8e88e628fdba6508 Mon Sep 17 00:00:00 2001 From: Will Jordan Date: Tue, 16 Nov 2021 21:10:19 +0100 Subject: [PATCH] Fix crash on macOS (AS) when dualshock4 is removed (cherry picked from commit 283e31a3e23a2b11ccbb9879b4832abef6ded50f) --- platform/osx/joypad_osx.cpp | 7 +++++-- platform/osx/joypad_osx.h | 12 ++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/platform/osx/joypad_osx.cpp b/platform/osx/joypad_osx.cpp index 3346c1ce1bb..e48799aa528 100644 --- a/platform/osx/joypad_osx.cpp +++ b/platform/osx/joypad_osx.cpp @@ -66,6 +66,7 @@ void joypad::free() { if (ff_device) { FFDeviceReleaseEffect(ff_device, ff_object); FFReleaseDevice(ff_device); + ff_device = nullptr; memfree(ff_axes); memfree(ff_directions); } @@ -250,7 +251,7 @@ void JoypadOSX::_device_added(IOReturn p_res, IOHIDDeviceRef p_device) { if (is_joypad(p_device)) { configure_joypad(p_device, &new_joypad); #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (IOHIDDeviceGetService != NULL) { + if (IOHIDDeviceGetService) { #endif const io_service_t ioservice = IOHIDDeviceGetService(p_device); if ((ioservice) && (FFIsForceFeedback(ioservice) == FF_OK) && new_joypad.config_force_feedback(ioservice)) { @@ -355,6 +356,7 @@ bool JoypadOSX::configure_joypad(IOHIDDeviceRef p_device_ref, joypad *p_joy) { { \ if (ret != FF_OK) { \ FFReleaseDevice(ff_device); \ + ff_device = nullptr; \ return false; \ } \ } @@ -374,6 +376,7 @@ bool joypad::config_force_feedback(io_service_t p_service) { return true; } FFReleaseDevice(ff_device); + ff_device = nullptr; return false; } #undef FF_ERR @@ -608,7 +611,7 @@ JoypadOSX::JoypadOSX() { if (array) { hid_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); - if (hid_manager != NULL) { + if (hid_manager) { config_hid_manager(array); } CFRelease(array); diff --git a/platform/osx/joypad_osx.h b/platform/osx/joypad_osx.h index 0ec0bb72ead..cd7d863108d 100644 --- a/platform/osx/joypad_osx.h +++ b/platform/osx/joypad_osx.h @@ -66,14 +66,14 @@ struct joypad { int id = 0; bool offset_hat = false; - io_service_t ffservice; /* Interface for force feedback, 0 = no ff */ + io_service_t ffservice = 0; /* Interface for force feedback, 0 = no ff */ FFCONSTANTFORCE ff_constant_force; - FFDeviceObjectReference ff_device; - FFEffectObjectReference ff_object; - uint64_t ff_timestamp; - LONG *ff_directions; + FFDeviceObjectReference ff_device = nullptr; + FFEffectObjectReference ff_object = nullptr; + uint64_t ff_timestamp = 0; + LONG *ff_directions = nullptr; FFEFFECT ff_effect; - DWORD *ff_axes; + DWORD *ff_axes = nullptr; void add_hid_elements(CFArrayRef p_array); void add_hid_element(IOHIDElementRef p_element);