Skip to content

Commit

Permalink
ALPRCamera removeFromSuperview called before session ended
Browse files Browse the repository at this point in the history
Prevent crashes:

Fatal Exception: NSGenericException
*** Collection <CALayerArray: 0x282781230> was mutated while being enumerated.
-[ALPRCamera removeFromSuperview]
  • Loading branch information
Francois Nadeau authored Aug 1, 2019
1 parent 6458616 commit 49247cb
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions ios/ALPRCameraManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -439,24 +439,27 @@ - (void)stopSession {
self.camera = nil;
return;
#endif
dispatch_async(self.sessionQueue, ^{
self.camera = nil;
[self.previewLayer removeFromSuperlayer];
[self.session commitConfiguration];
[self.session stopRunning];
for(AVCaptureInput *input in self.session.inputs) {
[self.session removeInput:input];
}
// Make sure that we are on the main thread when we are
// ending the session, otherwise we may get an exception:
// Fatal Exception: NSGenericException
// *** Collection <CALayerArray: 0x282781230> was mutated while being enumerated.
// -[ALPRCamera removeFromSuperview]
self.camera = nil;
[self.previewLayer removeFromSuperlayer];
[self.session commitConfiguration];
[self.session stopRunning];
for(AVCaptureInput *input in self.session.inputs) {
[self.session removeInput:input];
}

for(AVCaptureOutput *output in self.session.outputs) {
[self.session removeOutput:output];
}
for(AVCaptureOutput *output in self.session.outputs) {
[self.session removeOutput:output];
}

[[NSNotificationCenter defaultCenter] removeObserver:self];
if ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
});
[[NSNotificationCenter defaultCenter] removeObserver:self];
if ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
}

- (void)initializeCaptureSessionInput:(NSString *)type {
Expand Down

0 comments on commit 49247cb

Please sign in to comment.