Переглянути джерело

device: fix crash when unplugging certain devices on macOS

Fixes #621
rdb 6 роки тому
батько
коміт
239dc40032
1 змінених файлів з 4 додано та 1 видалено
  1. 4 1
      panda/src/device/ioKitInputDevice.cxx

+ 4 - 1
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();
 }