Skip to content

Bluetooth Issue#112

Merged
NullPointerDepressiveDisorder merged 1 commit intomainfrom
bug/bluetooth-2
Feb 17, 2026
Merged

Bluetooth Issue#112
NullPointerDepressiveDisorder merged 1 commit intomainfrom
bug/bluetooth-2

Conversation

@NullPointerDepressiveDisorder
Copy link
Owner

This pull request addresses a bug in the DeviceMonitor class where a stale global reference (gDeviceMonitor) could prevent new instances from registering correctly if start() failed (for example, when no device is found). The fix ensures that stop() cleans up the global reference even when the monitor is not running, preventing callbacks from being dispatched to a dead instance. A new test is added to verify this behavior.

Bug fix for global reference cleanup:

  • Updated DeviceMonitor.stop() to clean up the global reference (gDeviceMonitor) even if isRunning is false, ensuring that failed start() attempts do not leave a stale reference and block future monitors from registering.

Testing improvements:

  • Added testStopCleansUpGlobalReferenceWhenStartFailed to verify that after a failed start(), calling stop() properly clears the global reference, allowing a new DeviceMonitor to take ownership.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the DeviceMonitor class where a stale global reference (gDeviceMonitor) could prevent new monitor instances from functioning correctly after a failed start() call. The fix ensures proper cleanup of global state even when monitoring never successfully started, which is critical for the C callback infrastructure used by the MultitouchSupport framework.

Changes:

  • Modified DeviceMonitor.stop() to clean up gDeviceMonitor global reference even when isRunning is false
  • Added test case to verify global reference cleanup after failed start() attempts

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
MiddleDrag/Managers/DeviceMonitor.swift Added early-return path in stop() to clean up global reference (gDeviceMonitor) when monitor owns the reference but was never started, preventing stale references from blocking future monitor instances
MiddleDrag/MiddleDragTests/DeviceMonitorTests.swift Added testStopCleansUpGlobalReferenceWhenStartFailed to verify that stop() properly clears global reference after failed start(), allowing new monitors to take ownership

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sentry
Copy link
Contributor

sentry bot commented Feb 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@NullPointerDepressiveDisorder NullPointerDepressiveDisorder merged commit f9030da into main Feb 17, 2026
12 checks passed
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder deleted the bug/bluetooth-2 branch February 17, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MiddleDrag starts disabled after every Mac reboot (likely because I am using a Bluetooth Magic Trackpad)

1 participant

Comments