expo: [expo-camera/next][ios] crash with `facing="front"` & `useRef`

Minimal reproducible example

https://github.com/younes0/expo-camera-front-ios-crash

What platform(s) does this occur on?

iOS

Did you reproduce this issue in a development build?

Yes

Summary

happens with expo-camera since version 14.0.5.

export default function App() {
  const cameraRef = React.useRef();

  return (
    <CameraView
      facing="front"
      ref={cameraRef}
      style={StyleSheet.absoluteFill}
    />
  );
}

will result in a crash on ios. removing facing="front" or ref={cameraRef} prevents the crash.

on my project, sentry would report: "opacity > setAlpha: > Attempted to dereference garbage pointer at 0x10."

Environment

expo-env-info 1.2.0 environment info: System: OS: Linux 5.15 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish) Shell: 3.3.1 - /usr/bin/fish Binaries: Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node Yarn: 1.22.19 - /mnt/c/Users/youne/AppData/Roaming/npm/yarn npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm npmPackages: expo: ~50.0.8 => 50.0.8 react: 18.2.0 => 18.2.0 react-native: 0.73.4 => 0.73.4 Expo Workflow: managed

Expo Doctor Diagnostics

✔ Check Expo config for common issues ✔ Check package.json for common issues ✔ Check dependencies for packages that should not be installed directly ✔ Check for common project setup issues ✔ Check for issues with metro config ✔ Check npm/ yarn versions ✔ Check that packages match versions required by installed Expo SDK ✔ Check Expo config (app.json/ app.config.js) schema ✔ Check for legacy global CLI installed locally ✔ Check that native modules do not use incompatible support packages ✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn’t find any issues with the project!

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Reactions: 1
  • Comments: 24

Most upvoted comments

Hi everyone, this was a regression in 14.1.2. 14.1.3 will be released later today. Sorry for the inconvenience

still not working for me on ios, with expo-camera 14.1.2, not matter if my dev-client is presenting or not, when I try to open the screen where my camera is, it just crashes

Your app just crashed. See the error below.
NSGenericException: *** -[AVCaptureSession startRunning] startRunning may not be called between calls to beginConfiguration and commitConfiguration
  0   CoreFoundation                      0x00000001d0a4eda0 6A07CBE8-4F65-3DBC-B59D-C1A188A7B95D + 40352
  1   libobjc.A.dylib                     0x00000001c9b0c3d0 objc_exception_throw + 60
  2   AVFCapture                          0x00000001ea53e3c0 FC3C1F8B-3A2F-384C-B719-019BE94A98EA + 172992
  3   HazeExplrDEV                        0x0000000100c01728 $s10ExpoCamera0B8ViewNextC12startSession33_0C10F0D99CA71488C42A4C34CA4B3A30LLyyFyyYbcfU_yyYbcfU_ + 132
  4   HazeExplrDEV                        0x0000000100bc543c $sIegh_IeyBh_TR + 48
  5   libdispatch.dylib                   0x00000001d7f0deac B74732B5-D7FE-34A4-9346-41945701F020 + 16044
  6   libdispatch.dylib                   0x00000001d7f11330 B74732B5-D7FE-34A4-9346-41945701F020 + 29488
  7   libdispatch.dylib                   0x00000001d7f24908 B74732B5-D7FE-34A4-9346-41945701F020 + 108808
  8   libdispatch.dylib                   0x00000001d7f1540c B74732B5-D7FE-34A4-9346-41945701F020 + 46092
  9   libdispatch.dylib                   0x00000001d7f160a4 B74732B5-D7FE-34A4-9346-41945701F020 + 49316
  10  libdispatch.dylib                   0x00000001d7f20cdc B74732B5-D7FE-34A4-9346-41945701F020 + 93404
  11  libsystem_pthread.dylib             0x00000002303d7ddc _pthread_wqthread + 288
  12  libsystem_pthread.dylib             0x00000002303d7b7c start_wqthread + 8

Will the release include the fix for the android crash that has been merge (but apparently not package released) https://github.com/expo/expo/pull/27126 ?

I’ve updated the repo to showcase the crash: https://github.com/younes0/expo-camera-front-ios-crash

@sergeushenecz @toni1703 14.1.2 introduced this crash indeed. Would it be possible to check the XCode logs to help @alanjhughes ? I will but not before tomorrow.

I 've reverted to 14.1.1 and all works

@olivermihaly same issue hare.

@alanjhughes it’s fixed now, thanks! I used patch-package and built a new dev client.

For me it reproduces everytime, it happens in release production builds also so im not sure how the dev menu would be the cause there.

For my situation I can get around this problem by only switching to the front facing camera after the ‘onCameraReady’ event in fired.

Confirm I have the exact same behaviour, im currently on 14.0.5.

My crash refers to onAppForegrounded() as the parent function.

partial apply for closure #1 in CameraViewNext.onAppForegrounded()
startRunning may not be called between calls to beginConfiguration and commitConfiguration

I presume when using the forward facing camera, the barcode scanner is unavailable resulting in a blocking function call and that asynchronous function is taking the full 0.5 seconds before releasing and commiting the configuration?

Perhaps the function should check if its initiated in ‘front’ orientation and run the old version of the code instead.

Hi @alanjhughes - crash remains with a new dev client using yarn and latest version 14.0.6 Note that crash will only happen on launch. If you comment facing or ref before and uncomment after launch, it won’t crash.

I get the same error whenever the facing prop is set. Removing it seems to solve the issue.