Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes on old MacOS versions #147

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

evdokimovs
Copy link

@evdokimovs evdokimovs commented Jan 25, 2024

Synopsis

It was discovered that flutter-webrtc crashes on old MacOS versions (< 10.15). The problem arises from the utilization of the newer AVCaptureDeviceDiscoverySession API, which is not supported on these legacy systems.

We've opted for the newer API since the old one is deprecated and doesn't function correctly on the more recent versions of MacOS.

Solution

To address this, we can add a conditional check based on the MacOS version where the code is executed. This involves using an if statement to determine the appropriate API to call, like so:

if (@available(macOS 10.15, *)) {
  // Use new API
} else {
  // Use old API
}

However, simply adding this conditional check can lead to a program crash at the start, triggered by dyld, as it cannot locate symbols of the newer API during the initial execution. To mitigate this, it is necessary to instruct the compiler to weakly link the system library containing the new API. Weakly linking the library means that symbol checks will be not performed at startup, avoiding a crash. Since the if statement ensures that the code for the new API is never executed on older systems, this approach will not crash a program.

Checklist

  • Created PR:
    • In draft mode
    • Name contains issue reference
    • Has type and k:: labels applied
    • Has assignee
  • Before review:
    • Documentation is updated (if required)
    • Tests are updated (if required)
    • Changes conform code style
    • CHANGELOG entry is added (if required)
    • FCM (final commit message) is posted or updated
    • Draft mode is removed
  • Review is completed and changes are approved
    • FCM (final commit message) is approved
  • Before merge:
    • Milestone is set
    • PR's name and description are correct and up-to-date
    • All temporary labels are removed

@evdokimovs evdokimovs added enhancement Improvement of existing features or bugfix k::refactor Refactoring, technical debt elimination and other improvements of existing code base platform::macos Specific to macOS platform labels Jan 25, 2024
@evdokimovs evdokimovs self-assigned this Jan 25, 2024
@evdokimovs
Copy link
Author

FCM

Fix crashes on old MacOS versions (#147)

@evdokimovs evdokimovs marked this pull request as ready for review January 25, 2024 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix k::refactor Refactoring, technical debt elimination and other improvements of existing code base platform::macos Specific to macOS platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants