From 239dc400325fa530316fbc40a60987eca353ff89 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 14 Apr 2019 22:11:20 +0200 Subject: [PATCH] device: fix crash when unplugging certain devices on macOS Fixes #621 --- panda/src/device/ioKitInputDevice.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/panda/src/device/ioKitInputDevice.cxx b/panda/src/device/ioKitInputDevice.cxx index da1369932e..8468fd4816 100644 --- a/panda/src/device/ioKitInputDevice.cxx +++ b/panda/src/device/ioKitInputDevice.cxx @@ -22,8 +22,11 @@ #include "mouseButton.h" static void removal_callback(void *ctx, IOReturn result, void *sender) { - IOKitInputDevice *input_device = (IOKitInputDevice *)ctx; + // We need to hold a reference to this because it may otherwise be destroyed + // during the call to on_remove(). + PT(IOKitInputDevice) input_device = (IOKitInputDevice *)ctx; nassertv(input_device != nullptr); + nassertv(input_device->test_ref_count_integrity()); input_device->on_remove(); }