[BUG] [iOS] CameraView: AVCaptureVideoPreviewLayer deallocated while key value observers were still registered
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 65/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- csharp, ios
- Ambito
- mobile-dev
Direzione di ricerca
Start by reading the iOS CameraManager implementation, especially Dispose() and PlatformStopCameraPreview, and trace how rotationCoordinator observes previewView.Layer. Verify that coordinator cleanup occurs before preview-view disposal and remains safe for stopped previews. A public reproduction is unavailable, so success requires a regression test or reproducible lifecycle scenario showing no exception after transient page navigation and finalization.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
On iOS 17+, the app aborts with an NSInternalInconsistencyException some seconds after leaving a page that hosts a CameraView. The page is transient (not reused) and the CameraView handler is never disconnected explicitly, so the page and its native views are released later by the GC.
NSInternalInconsistencyException: An instance of class AVCaptureVideoPreviewLayer was deallocated while key value observers were still registered with it.
Current observation info:
Observer: 0x0, Key path: bounds, Options: <New: YES, Old: YES, Prior: NO>
Observer: 0x0, Key path: frame, Options: <New: YES, Old: YES, Prior: NO>
Native stack of the crashed (main) thread:
+[__NSObject_Disposer drain:]
Foundation.NSObject.ReleaseManagedRef
xamarin_release_managed_ref
NSKVODeallocate
objc_exception_throw
The release comes from the finalizer path (NSObject_Disposer), not from an explicit Dispose.
Analysis (from reading CameraManager for macios in 6.1.0):
- On iOS 17+,
PlatformConnectCameracreates anAVCaptureDeviceRotationCoordinatorbound to the preview view's layer:rotationCoordinator = new AVCaptureDeviceRotationCoordinator(captureDevice, previewView.Layer). - The only observers registered on the preview layer appear to be the coordinator's (
bounds/frame). This is our interpretation; we have not confirmed it in Apple's code. CameraManager.Dispose()disposespreviewViewbeforerotationCoordinator. When the handler is not disconnected, both are finalized in arbitrary order, so the layer can be deallocated while the coordinator still observes it.
Expected Behavior
Leaving a page with a CameraView (with or without an explicit handler disconnect) never aborts the app. The preview layer is never deallocated while an observer is still registered on it.
Suggested fix:
- In
CameraManager.Dispose(), dispose the rotation coordinator before the preview view, and set it to null. - Consider releasing the coordinator in
PlatformStopCameraPreviewas well, so a stopped preview leaves no observer bound to the layer.
Steps To Reproduce
- Register a page with a
CameraViewas transient and navigate to it (Shell push); start the preview. - Stop the preview and navigate back. The page is not reused and the handler is not disconnected.
- Keep using the app until the GC collects the old page. The app aborts with the exception above.
It is intermittent because it depends on GC timing and finalization order (one occurrence in our field reports so far).
Link to public reproduction project repository
No public reproduction yet: the crash depends on GC timing and has been seen once in the field. The analysis above is from the shipped 6.1.0 assembly. Happy to build a minimal repro if it helps.
Environment
- .NET MAUI CommunityToolkit: CommunityToolkit.Maui.Camera 6.1.0
- OS: iOS 27.0.1 (iPhone18,2); the rotation coordinator path is iOS 17+
- .NET MAUI: 10.0.110
Anything else?
The crash happens on the main thread during the disposer drain, with no managed frame of the app involved.
- Lingua principale
- C#
- Stelle
- 2.7k
- Fork
- 502
- Merge medio
- 11h 10m
- PR unite (30g)
- 50
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CommunityToolkit/Maui
-
new proposal
Difficoltà 5/5 Più di una settimana Idoneità per principianti 12/100
CommunityToolkit/Maui#3449 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug unverified
Difficoltà 3/5 1-2 giorni Idoneità per principianti 63/100
CommunityToolkit/Maui#3443 ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] Keep the device tests on the newest OS releases automaticallyForse già presa @TheCodeTraveler l’ha presa 3 giorni fa. Apertaapproved champion proposal
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
CommunityToolkit/Maui#3438 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
new proposal
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
CommunityToolkit/Maui#3436 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] The popup positioning changing if SetShouldUseStatusBarBehaviorOnAndroidModalPage is trueApertabug unverified
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
CommunityToolkit/Maui#3425 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di CommunityToolkit/Maui
Issue simili
-
area: core bug help wanted ready
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ZaidX88/sluice#265 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area: remote bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Install a C# EnvironmentAperta📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
CodeYourFuture/Module-Tools#712 ·
-
:watch: Not Triaged dotnet-fundamentals/svc
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
A: Mapping P3: Standard T: New Feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
space-wizards/space-station-14#46878 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno