Skip to content

Fix: Multitouch stability during rapid system changes#96

Merged
NullPointerDepressiveDisorder merged 1 commit into
mainfrom
seer/fix/multitouch-stability
Feb 6, 2026
Merged

Fix: Multitouch stability during rapid system changes#96
NullPointerDepressiveDisorder merged 1 commit into
mainfrom
seer/fix/multitouch-stability

Conversation

@sentry

@sentry sentry Bot commented Feb 6, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes MIDDLEDRAG-G. The issue was that: Rapid connectivity changes triggered overlapping multitouch device restarts, causing the MultitouchSupport framework's internal thread to CFRelease a deallocated device reference.

  • Increased frameworkCleanupDelay and restartCleanupDelay to 0.5s to prevent crashes during rapid connectivity changes and restart cycles.
  • Added os_unfair_lock around MTDeviceStop calls to prevent CFRelease(NULL) crashes from concurrent access.
  • Increased minimumRestartInterval to 0.6s to debounce rapid restart triggers and mitigate race conditions.

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📚 Documentation update
  • 🔧 Refactor (code change that neither fixes a bug nor adds a feature)
  • 🧪 Test improvement

Related Issues

Fixes MIDDLEDRAG-G

Testing Performed

  • Tested with built-in trackpad
  • Tested with Magic Trackpad (if available)
  • Verified system gestures (Mission Control, etc.) still work
  • [ ] Tested in target apps (list any specific apps tested):

Checklist

  • My code follows the project's code style guidelines
  • I have tested my changes thoroughly
  • I have added comments for non-obvious logic
  • My changes don't break existing functionality
  • I have updated documentation if needed

Code Coverage

  • I have added tests for new functionality (where applicable)
  • My changes meet the 80% patch coverage requirement

Screenshots / Recordings

Additional Notes

This fix was generated by Seer in Sentry, triggered by Karan Mohindroo. 👁️ Run ID: 9814512

Not quite right? Click here to continue debugging with Seer.

@sentry

sentry Bot commented Feb 6, 2026

Copy link
Copy Markdown
Contributor Author

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
MiddleDrag/Managers/DeviceMonitor.swift 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@NullPointerDepressiveDisorder
NullPointerDepressiveDisorder marked this pull request as ready for review February 6, 2026 03:07
Copilot AI review requested due to automatic review settings February 6, 2026 03:07
@NullPointerDepressiveDisorder NullPointerDepressiveDisorder added the bug Something isn't working label Feb 6, 2026
@NullPointerDepressiveDisorder
NullPointerDepressiveDisorder merged commit df9d293 into main Feb 6, 2026
10 checks passed
@NullPointerDepressiveDisorder
NullPointerDepressiveDisorder deleted the seer/fix/multitouch-stability branch February 6, 2026 03:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 addresses a critical crash (MIDDLEDRAG-G) caused by race conditions in the MultitouchSupport framework during rapid connectivity changes. The fix employs a defense-in-depth strategy combining increased timing delays and explicit locking to prevent the framework's internal thread from accessing deallocated device references during cleanup.

Changes:

  • Increased framework cleanup delays from 100-250ms to 500ms to allow proper resource cleanup during rapid connectivity toggling
  • Increased minimum restart interval from 300ms to 600ms to better debounce rapid restart triggers
  • Added os_unfair_lock protection around MTDeviceStop calls to prevent concurrent access during critical shutdown operations

Reviewed changes

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

File Description
MiddleDrag/Managers/MultitouchManager.swift Updated timing constants (restartCleanupDelay and minimumRestartInterval) with improved documentation explaining the rationale for rapid connectivity change scenarios
MiddleDrag/Managers/DeviceMonitor.swift Increased frameworkCleanupDelay and added lock protection around MTDeviceStop calls to prevent concurrent framework access during device shutdown

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

/// Increased from 50ms to handle rapid foreground/background toggling scenarios.
static let frameworkCleanupDelay: TimeInterval = 0.1
/// Value determined empirically: 500ms is sufficient to avoid CFRelease(NULL) crashes
/// and EXC_BREAKPOINT exceptions during rapid connectivity changes (wifi ↔ none).

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

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

The term "wifi" should be capitalized as "Wi-Fi" for proper spelling.

Suggested change
/// and EXC_BREAKPOINT exceptions during rapid connectivity changes (wifi ↔ none).
/// and EXC_BREAKPOINT exceptions during rapid connectivity changes (Wi-Fi ↔ none).

Copilot uses AI. Check for mistakes.
/// handle rapid foreground/background toggling that can trigger multiple restart cycles.
static let restartCleanupDelay: TimeInterval = 0.25
/// Value determined empirically: 500ms is sufficient to avoid CFRelease(NULL) crashes
/// and EXC_BREAKPOINT exceptions during rapid connectivity changes (wifi ↔ none).

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

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

The term "wifi" should be capitalized as "Wi-Fi" for proper spelling.

Copilot uses AI. Check for mistakes.
/// by waiting at least this long after the last restart completed.
static let minimumRestartInterval: TimeInterval = 0.3
/// When multiple restart triggers occur in rapid succession (e.g., rapid connectivity
/// changes wifi ↔ none), we debounce them by waiting at least this long after the

Copilot AI Feb 6, 2026

Copy link

Choose a reason for hiding this comment

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

The term "wifi" should be capitalized as "Wi-Fi" for proper spelling.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants