[SDK 34] Camera crashing on standalone iOS

Hey expo team!

Currently facing the following problem:

On iOS, in our standalone production build, rendering <Camera/> immediately crashes the app. Tried the following

  • Doesn’t crash in the expo client on the iOS simulator in dev or production mode
  • Doesn’t crash in the expo client on my iOS device in dev or production mode
  • Doesn’t crash in the expo client on the Android simulator in dev mode
  • Does crash in the standalone production build of our app on my iOS device.

It crashes (completely exiting the app) before anything is logged to Sentry, which makes me think there’s a good chance this is happening on the “native” side. I checked and we’ve granted camera permissions to our app in the iOS settings.

I tried to reproduce it in snack but wasn’t able to import the Camera module, then realized I probably can’t reproduce it with the expo client anyway. I expo publish’d a few times to narrow it down and it seems to happen if we return <Camera/>; in our render function of the screen, like so

import { Camera } from 'expo-camera';
import React, { Component, Fragment } from 'react';
import {
  Platform,
} from 'react-native';

export default class CameraScreen extends Component {
  // ... [our original code]

  render() {
    if (Platform.OS === 'ios') {
      return <Camera/>; // if we instead return null here, doesn't crash
    }
    // ... [our original code]
  }
}

Best,
Raphy

1 Like

Looks like there’s existing discussion on github

Hey @raphaelrk, thanks for linking the issue! We just merged a fix for this this morning

Thanks @charliecruzan! Do you or @sjchmiela know when we can expect to include the fix in our app? Is it an Expo build server fix, or just a package update we should keep an eye out for on npm?

1 Like

Sounds like rebuilding will be the solution, so I’ll be watching for updates on GH: expo-camera work well on Expo Client, but it make crash app when I build ios standalone app · Issue #5160 · expo/expo · GitHub

In the meantime, I reverted my upgrade-to-SDK-34 commit and rebuilt with SDK 33 to get around the problem. That’s been working today, and then I’ll return to 34 with this fix in place.

@ddagradi should be fixed now! Go ahead and run expo build:ios :smile:

3 Likes

Y’all are heroes – thanks for the super fast open-source turn around!

Hi, standalone iOS still crashing

Can you get a crash report from Testflight?

Are you using the barcode scanner or face detector?

Hi @wodin for some reason neither Crashlytics nor Testflight seems to be generating crash reports. Very frustrating stuff. I’m using face detector. Here is the code that I am using.

OK, it will be very difficult to track down without a crash report. Do you get a crash report locally that you can manually symbolicate?

Another idea (although it might be a lot of effort): If you can build the app locally on your machine with a custom Expo SDK maybe you can try to use git bisect to find where the problem was introduced. For this you’d need to do something like clone GitHub - expo/react-native: A framework for building native apps with React. and then bisect between a version of the SDK that worked for you and the sdk-34.0.1 tag. This is not something I’ve done before with Expo, but I have used git bisect successfully for other things several times.

Hi @wodin, is this sufficient?

Last Exception Backtrace:
0 CoreFoundation 0x1bedcbea0 __exceptionPreprocess + 228
1 libobjc.A.dylib 0x1bdf9da40 objc_exception_throw + 55
2 CoreFoundation 0x1becd2674 +[NSException raise:format:] + 115
3 my app 0x1015622f8 +[FIRVision vision] + 87
4 my app 0x100413758 +[EXFaceDetector detectorForOptions:] + 1374040 (EXFaceDetector.m:79)
5 my app 0x100412c8c -[EXFaceDetector initWithOptions:] + 1371276 (EXFaceDetector.m:19)
6 my app 0x100414284 -[EXFaceDetectorManager tryEnablingFaceDetection] + 1376900 (EXFaceDetectorManager.m:133)
7 my app 0x100414090 -[EXFaceDetectorManager maybeStartFaceDetectionOnSession:withPreviewLayer:mirrored:] + 1376400 (EXFaceDetectorManager.m:117)
8 my app 0x100405d70 -[EXCamera maybeStartFaceDetection:] + 1318256 (EXCamera.m:545)
9 my app 0x100406540 __24-[EXCamera startSession]_block_invoke + 1320256 (EXCamera.m:610)
10 libdispatch.dylib 0x10458b824 0x104588000 + 14372
11 libdispatch.dylib 0x10458cdc8 0x104588000 + 19912
12 libdispatch.dylib 0x104594e6c 0x104588000 + 52844
13 libdispatch.dylib 0x104595b60 0x104588000 + 56160
14 libdispatch.dylib 0x10459fbfc 0x104588000 + 97276
15 libsystem_pthread.dylib 0x1be9e80dc _pthread_wqthread + 311
16 libsystem_pthread.dylib 0x1be9eacec start_wqthread + 3

Based on the stack trace and the code I suppose [[FIRVision vision] faceDetectorWithOptions:options] doesn’t like the supplied options?

+ (FIRVisionFaceDetector *)detectorForOptions:(FIRVisionFaceDetectorOptions *)options
{
  return [[FIRVision vision] faceDetectorWithOptions:options];
}

The above options come from EXFaceDetector’s initWithOptions method:

-(instancetype) initWithOptions:(FIRVisionFaceDetectorOptions *)options
{
  self = [super init];
  detector = [EXFaceDetector detectorForOptions:options];
  return self;
}

Those options come from EXFaceDetectorManager’s tryEnablingFaceDetection method where they are called _faceDetectorOptions:

[...]  
  if ([self isDetectingFaceEnabled]) {
    @try {
      self.faceDetector = [[EXFaceDetector alloc] initWithOptions:_faceDetectorOptions];
[...]

Those options come from EXFaceDetectorManager’s initWithOptions method:

- (instancetype)initWithOptions:(NSDictionary*)options
{
  if (self = [super init]) {
[...]
    _faceDetectorOptions = [EXFaceDetectorUtils mapOptions:options];
[...]
}

Then my lack of Objective-C experience makes it a bit difficult for me to follow :laughing:

@he1nr1ch, for the sake of figuring out what triggers this bug, does changing the faceDetectorSettings avoid/change the crash?

Hi @sjchmiela, does @he1nr1ch’s stack trace help to track down this bug?

Hi @wodin, changing the settings had no effect. Still crashes

Ok, well you might have to wait for one of the Expo devs to have a look next week. It might be a good idea to open a new issue and including the details from your comments on the other bug and also the stack trace.

Unless your Objective-C skills are better than mine :grin:

Thank you very much for all of your help. Hopefully this can get resolved quickly. I did however notice that my report looks almost identical to the one that was used to solve this issue, with the exception of line 7 on my own crash report. Any idea as to why this might be?

hmmm…, I see. I think in that case the face detector wasn’t being used at all, so presumably the faceDetectorSettings were empty/missing. The fix was just to put the face detector creation inside try/catch. I am not sure why this doesn’t work around the crash in your case, but anyway, since you want to actually use the face detector the fix would not help you.

Maybe just post your stack trace to that bug then and point out the similarity to the other one, but say that you are in fact trying to use the face detector, unlike the person who posted the other stack trace.

EDIT:
I was going to suggest trying to build camerja to see if that also crashes for you, but it doesn’t seem to have been updated for SDK 34.

Maybe also keep an eye on this issue:

https://github.com/expo/expo/issues/5373

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.