Skip to content

🐛 oppening the camera crash application on iOS(not on android) #3644

@Achref124

Description

@Achref124

What's happening?

i implemented react-native-vision-camera on my project and it works on android, but when i want to test it on iOS, app is crashing when i open the camera(i am using a real device not emulator)

Reproduceable Code

const CameraModal = ({visible, setVisible}) => {
  const {flashlitePhotoState, appColor} = useSelector(
    (state: any) => state.authUser,
  );
  const dispatch = useDispatch();

  const [picture, setPicture] = useState(null);
  const [loading, setLoading] = useState(false);
  const [validPicture, setValidPicture] = useState(false);
  const [direction, setDirection] = useState<'front' | 'back'>('back');
  const [flash, setFlash] = useState<'off' | 'on'>(flashlitePhotoState);
  console.log(flashlitePhotoState, 'flashlitePhotoState');
  const cameraRef = useRef<Camera>(null);
  const device = useCameraDevice('back');
  const {hasPermission, requestPermission} = useCameraPermission();
  console.log(device?.hardwareLevel, 'hasPermission');
  const isActive = visible;

  useEffect(() => {
    if (flashlitePhotoState == 'off') setFlash('off');
    else setFlash('on');
  }, [flashlitePhotoState]);

  useEffect(() => {
    if (validPicture) validatePicture();
  }, [validPicture]);

  const validatePicture = async () => {
    const compressed = await ImageCompress.compress(picture, {
      compressionMethod: 'auto',

      width: 1920, // Augmenter la largeur
      height: 2560, // Ajuster la taille en fonction de l'image
      quality: 0.85,
      input: 'uri',
      returnableOutputType: 'base64',
    });

    setVisible({
      orientation: 0,
      base64: compressed,
    });
    setPicture(null);
    setValidPicture(false);
  };

  const takePicture = async () => {
    if (!cameraRef.current) return;
    setLoading(true);
    try {
      const photo = await cameraRef.current.takePhoto({
        qualityPrioritization: 'speed',
        flash: flashlitePhotoState,
      });
      setPicture(`file://${photo.path}`);
    } catch (e) {
      console.error('Erreur prise photo', e);
    }
    setLoading(false);
  };

  const changeFlashState = () => {
    const next =
      flashlitePhotoState === 'off'
        ? 'on'
        : flashlitePhotoState == 'on'
        ? 'off'
        : 'on';

    dispatch({
      type: 'authUser/setFlashlitePhotoState',
      payload: next,
    });
  };

  return (
    <Modal visible={visible} animationType="slide" transparent={true}>
      {picture ? (
        <PictureView
          picture={picture}
          setPicture={setPicture}
          setValidPicture={setValidPicture}
        />
      ) : (
        <View style={styles.containerPicture}>
          {device   && (<Camera
            
            device={device}
            isActive={true}
          />)}

          <View style={[styles.btnControlPic, {zIndex: 1000}]}>
            <IconIOC
              onPress={() => setVisible()}
              name="close"
              size={40}
              color={appColor}
            />
            <IconIOC
              onPress={() =>
                setDirection(prev => (prev === 'back' ? 'front' : 'back'))
              }
              name="camera-reverse"
              size={40}
              color={appColor}
            />
            <IconCOM
              onPress={changeFlashState}
              name={`flash${flashlitePhotoState == 'off' ? '-off' : ''}`}
              size={40}
              color={appColor}
            />
          </View>

          {loading ? (
            <View style={{justifyContent: 'center'}}>
              <ActivityIndicator
                style={styles.btnTakePic}
                color={appColor}
                size="large"
              />
            </View>
          ) : (
            <TouchableOpacity
              activeOpacity={0.5}
              style={styles.btnTakePic}
              onPress={takePicture}>
              <MaterialCommunityIcons
                name="camera"
                size={40}
                color={appColor}
              />
            </TouchableOpacity>
          )}
        </View>
      )}
    </Modal>
  );
};

Relevant log output

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'
*** First throw call stack:
(0x1a2b48f20 0x19a9f32b8 0x1a2adae6c 0x1a2adaa88 0x106df86a8 0x106ddd638 0x101b367bc 0x101b3834c 0x106ddd5c8 0x10698659c 0x106a079b8 0x106a0d3a4 0x106a0d358 0x106a0d304 0x106a0d2d8 0x106a0c15c 0x106ff7c44 0x106ff7a38 0x1066bbbc4 0x1066c1bdc 0x1067e3a94 0x106816f7c 0x106816d60 0x106816ce8 0x106816c9c 0x106815a1c 0x106ff7afc 0x106ff797c 0x106c8f1f8 0x1b9121fac 0x1b99c0424 0x1b9a18508 0x1ba22cd38 0x1ba2295c0 0x1ba2295c0 0x1ba2295c0 0x1ba22a7a8 0x1ba2295c0 0x1ba2295c0 0x1ba22a7a8 0x1ba22a7a8 0x1ba2003d4 0x1b98d53f8 0x1b9133c98 0x106c87410 0x10693a2a8 0x10693cd10 0x106be1e20 0x106c83eac 0x106dc01a8 0x106dbfffc 0x106dbfbd0 0x106dc970c 0x106dc96d4 0x106dc9684 0x106dc9658 0x106dc84e4 0x106ad52ac 0x106ad5254 0x106bc9150 0x106bc90b0 0x106bc9068 0x106bc9044 0x106bc7d7c 0x10654c810 0x10654c7c0 0x106565730 0x1065925e4 0x106597168 0x10659710c 0x1065970c4 0x1065970a0 0x106595e64 0x10654c810 0x10654c7c0 0x10659237c 0x1a2b2ac9c 0x1a2b18dec 0x1a2b18ad0 0x1a2b17cd8 0x106bb3498 0x1a1a4f428 0x1ff59a06c 0x1ff5950d8)
libc++abi: terminating due to uncaught exception of type NSException

Camera Device

{ supportsFocus: true,
  hasFlash: true,
  position: 'back',
  minZoom: 1,
  maxZoom: 16,
  minFocusDistance: 12,
  minExposure: -8,
  isMultiCam: false,
  sensorOrientation: 'portrait',
  formats: 
   [ { minFps: 1,
       minISO: 32,
       photoHeight: 3024,
       videoHeight: 144,
       videoWidth: 192,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 64.74187469482422,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 4032,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 3024,
       videoHeight: 144,
       videoWidth: 192,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 64.74187469482422,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 4032,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 3024,
       videoHeight: 288,
       videoWidth: 352,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 60.320228576660156,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 3696,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 3024,
       videoHeight: 288,
       videoWidth: 352,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 60.320228576660156,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 3696,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 3024,
       videoHeight: 360,
       videoWidth: 480,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 64.74187469482422,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 4032,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 3024,
       videoHeight: 360,
       videoWidth: 480,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 64.74187469482422,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 4032,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 3024,
       videoHeight: 480,
       videoWidth: 640,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 64.74187469482422,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 4032,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 3024,
       videoHeight: 480,
       videoWidth: 640,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 64.74187469482422,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 4032,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 1512,
       videoHeight: 480,
       videoWidth: 640,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 64.74187469482422,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 2016,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 1512,
       videoHeight: 480,
       videoWidth: 640,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 64.74187469482422,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'off' ],
       photoWidth: 2016,
       maxISO: 3072 },
     { minFps: 1,
       minISO: 32,
       photoHeight: 2384,
       videoHeight: 540,
       videoWidth: 960,
       autoFocusSystem: 'phase-detection',
       fieldOfView: 69.65403747558594,
       supportsPhotoHdr: false,
       supportsDepthCapture: false,
       supportsVideoHdr: false,
       maxFps: 60,
       videoStabilizationModes: [ 'auto', 'cinematic', 'off', 'standard', 'cinematic-extended' ],
       photoWidth: 4224,
       maxISO: [TOO BIG formatValueCalls 201 exceeded limit of 200] },
     [TOO BIG formatValueCalls 202 exceeded limit of 200],
     [TOO BIG formatValueCalls 203 exceeded limit of 200],
     [TOO BIG formatValueCalls 204 exceeded limit of 200],
     [TOO BIG formatValueCalls 205 exceeded limit of 200],
     [TOO BIG formatValueCalls 206 exceeded limit of 200],
     [TOO BIG formatValueCalls 207 exceeded limit of 200],
     [TOO BIG formatValueCalls 208 exceeded limit of 200],
     [TOO BIG formatValueCalls 209 exceeded limit of 200],
     [TOO BIG formatValueCalls 210 exceeded limit of 200],
     [TOO BIG formatValueCalls 211 exceeded limit of 200],
     [TOO BIG formatValueCalls 212 exceeded limit of 200],
     [TOO BIG formatValueCalls 213 exceeded limit of 200],
     [TOO BIG formatValueCalls 214 exceeded limit of 200],
     [TOO BIG formatValueCalls 215 exceeded limit of 200],
     [TOO BIG formatValueCalls 216 exceeded limit of 200],
     [TOO BIG formatValueCalls 217 exceeded limit of 200],
     [TOO BIG formatValueCalls 218 exceeded limit of 200],
     [TOO BIG formatValueCalls 219 exceeded limit of 200],
     [TOO BIG formatValueCalls 220 exceeded limit of 200],
     [TOO BIG formatValueCalls 221 exceeded limit of 200],
     [TOO BIG formatValueCalls 222 exceeded limit of 200],
     [TOO BIG formatValueCalls 223 exceeded limit of 200],
     [TOO BIG formatValueCalls 224 exceeded limit of 200],
     [TOO BIG formatValueCalls 225 exceeded limit of 200],
     [TOO BIG formatValueCalls 226 exceeded limit of 200],
     [TOO BIG formatValueCalls 227 exceeded limit of 200],
     [TOO BIG formatValueCalls 228 exceeded limit of 200],
     [TOO BIG formatValueCalls 229 exceeded limit of 200],
     [TOO BIG formatValueCalls 230 exceeded limit of 200],
     [TOO BIG formatValueCalls 231 exceeded limit of 200],
     [TOO BIG formatValueCalls 232 exceeded limit of 200],
     [TOO BIG formatValueCalls 233 exceeded limit of 200],
     [TOO BIG formatValueCalls 234 exceeded limit of 200],
     [TOO BIG formatValueCalls 235 exceeded limit of 200],
     [TOO BIG formatValueCalls 236 exceeded limit of 200],
     [TOO BIG formatValueCalls 237 exceeded limit of 200],
     [TOO BIG formatValueCalls 238 exceeded limit of 200] ],
  hasTorch: [TOO BIG formatValueCalls 239 exceeded limit of 200],
  id: [TOO BIG formatValueCalls 240 exceeded limit of 200],
  name: [TOO BIG formatValueCalls 241 exceeded limit of 200],
  supportsRawCapture: [TOO BIG formatValueCalls 242 exceeded limit of 200],
  neutralZoom: [TOO BIG formatValueCalls 243 exceeded limit of 200],
  supportsLowLightBoost: [TOO BIG formatValueCalls 244 exceeded limit of 200],
  maxExposure: [TOO BIG formatValueCalls 245 exceeded limit of 200],
  hardwareLevel: [TOO BIG formatValueCalls 246 exceeded limit of 200],
  physicalDevices: [TOO BIG formatValueCalls 247 exceeded limit of 200] }, 'Device'

Device

iphone 11 (ios 17.6.1)

VisionCamera Version

4.7.2

Can you reproduce this issue in the VisionCamera Example app?

I didn't try (⚠️ your issue might get ignored & closed if you don't try this)

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions