Skip to content

Conversation

@asabri97
Copy link
Collaborator

@asabri97 asabri97 commented Jan 6, 2026

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Fixes critical camera-related crashes on iOS and Android and improves camera restart behavior across app navigation 🔧📷✅

📊 Key Changes

  • 🧯 iOS crash fix when camera permission is denied/not granted
    • Added explicit camera authorization checks before camera setup (AVCaptureDevice.authorizationStatus).
    • Removed fatalError and replaced try! with safe do-catch + early returns to avoid hard crashes when no camera/input is available.
    • Hardened camera switching and zoom with nil checks and better failure handling/logging.
  • 🧵 Android crash fix: race condition when disposing YOLOView during inference
    • Introduced a @Volatile isStopped flag and checked it at multiple points in onFrame to avoid using closed resources after stop().
    • Made predictor shutdown safer with guarded close() handling.
  • 🔄 Improved camera restart/resume behavior on Android + Flutter example
    • Reordered initialization to set lifecycle owner before camera startup; camera starts only when permissions are granted.
    • Added a new platform method restartCamera and a Dart API YOLOViewController.restartCamera().
    • Example app forces a rebuild when navigating back to the camera screen to ensure the camera view restarts reliably.
  • 📦 Version bump + notes
    • Updated package version to 0.1.45 and documented fixes in CHANGELOG.md.

🎯 Purpose & Impact

  • 🚫➡️✅ Prevents fatal iOS crashes when users deny camera permission or when a camera device/input can’t be created, improving stability and user experience.
  • 🛑⚙️ Eliminates Android SIGSEGV/teardown crashes caused by inference callbacks running after resources are stopped/closed.
  • 🔁📱 More reliable camera recovery when returning to a camera screen or restarting the camera, reducing “black preview” / “camera won’t start” edge cases.
  • 🧩🧑‍💻 Better integration options for app developers via the new restartCamera() hook for manual recovery flows when needed.

@UltralyticsAssistant UltralyticsAssistant added bug Something isn't working fixed Bug has been resolved labels Jan 6, 2026
@UltralyticsAssistant
Copy link
Member

👋 Hello @asabri97, thank you for submitting a ultralytics/yolo-flutter-app 🚀 PR! This is an automated message to help with triage—an engineer will review and assist shortly 🧠🛠️

  • Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
  • Synchronize with Source: Confirm your PR is synchronized with the ultralytics/yolo-flutter-app main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
  • Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
  • Update Documentation: Update the relevant documentation for any new or modified features.
  • Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
  • Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
  • Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

Copy link
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

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

🔍 PR Review

Made with ❤️ by Ultralytics Actions

Solid crash-hardening overall: iOS permission/device nil handling looks correct and Android’s isStopped gating meaningfully reduces dispose/onFrame races. Main issue: the new restartCamera hook bypasses the existing permission/lifecycle guards by calling startCamera() directly; routing it through initCamera() (and/or adding precondition guards inside startCamera()) would make the fix robust. Example app rebuild trigger is likely effective but may introduce an extra initial rebuild.

💬 Posted 3 inline comments

@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

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

Files with missing lines Patch % Lines
lib/widgets/yolo_controller.dart 0.00% 4 Missing ⚠️
lib/core/yolo_inference.dart 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@asabri97 asabri97 merged commit 149b949 into main Jan 8, 2026
5 checks passed
@asabri97 asabri97 deleted the fix-ios-crash-camera-permissions branch January 8, 2026 10:47
@UltralyticsAssistant
Copy link
Member

Merged—huge thanks @asabri97 (and @onuralpszr for the contributions) for landing this stability-focused upgrade in the Flutter app.

“It is not the strongest of the species that survives… but the one most responsive to change.” — Charles Darwin

This PR is a great example of that mindset: proactively hardening camera flows across iOS and Android, removing crash paths (permission-denied, missing inputs, teardown races), and adding a practical restartCamera() hook that makes real-world navigation/recovery scenarios far more reliable. The 0.1.45 bump + clear changelog notes are the perfect finishing touch.

Appreciate the care, testing, and polish here—this will save developers (and users) a lot of frustration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixed Bug has been resolved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] App crashes with Fatal error when camera permission is denied (VideoCapture.swift:89)

4 participants