Skip to content

Fix/macos audio crash#358

Open
guidiguidi wants to merge 2 commits into
AyuGram:devfrom
guidiguidi:fix/macos-audio-crash
Open

Fix/macos audio crash#358
guidiguidi wants to merge 2 commits into
AyuGram:devfrom
guidiguidi:fix/macos-audio-crash

Conversation

@guidiguidi

@guidiguidi guidiguidi commented May 6, 2026

Copy link
Copy Markdown

Summary

This PR improves macOS smoothness by reducing two common sources of micro-stutters:

  • Audio device change “refresh storms” from CoreAudio notifications.
  • Excessive per-tick work while scrolling the chat list.

What changed

  • lib_webrtc (macOS):
    • Added lazy subscription to CoreAudio listeners.
    • Debounced default device + device list change handling, coalescing bursts into a single refresh.
  • Dialogs chat list:
    • Coalesced visible-range updates during scroll to avoid doing heavier preload/load-more logic on every scroll tick.
  • tgcalls (macOS):
    • Safer AudioDeviceModule creation (guarded against edge cases) and a small cache for audio-input availability checks to avoid repeated expensive queries.

Why

On macOS (especially newer versions), CoreAudio can emit bursts of device-related notifications even without user action. Forcing full device refreshes immediately can lead to periodic UI micro-stutters.
Similarly, chat list scrolling can trigger frequent visible-range updates; coalescing the heavy part improves perceived FPS and reduces jank.

Test plan

  • Scroll chat list fast for ~20–30 seconds → smoother scrolling, less jank
  • Plug/unplug or switch input/output device → device list updates correctly (no refresh storm)
  • (Optional) Start a call / open call settings → audio devices still initialize correctly

Notes

  • This is a performance-focused change; behavior should remain the same, with small expected delays (~tens/hundreds of ms) during bursty device-change events due to debouncing.

guidiguidi and others added 2 commits May 6, 2026 00:51
Investigation showed that immediate crashes occurred during microphone access due to unhandled exceptions in native layers.

Changes:
- Implemented @try-@catch guards around critical AVFoundation and CoreAudio calls.
- Migrated device discovery to AVCaptureDeviceDiscoverySession for better stability on macOS 10.15+.
- Enforced proper Platform namespace usage and added missing headers for media_audio_capture.
- Added defensive null checks for AVCaptureDevice objects.
Co-authored-by: Cursor <cursoragent@cursor.com>
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.

1 participant