mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
6.64k stars 983 forks source link

IllegalArgumentException: getCameraCharacteristics:1278: Unable to retrieve camera characteristics for unknown device 0: No such file or directory (-2)🐛 #2824

Closed Sharf8351 closed 2 weeks ago

Sharf8351 commented 2 weeks ago

What's happening?

As this issue happened in production. So, I don't have logs for it.

Steps to reproduce: Open the camera to Scan the QR-Code Choose allow "only this time" the camera opened shortly and the app crashed shortly after if the user wants to scan the code afterwards the camera doesn't open

AN 14 Pixel 7a

Reproduceable Code

const [cameraStatus, setCameraStatus] = useState<CameraStatus>('unknown');
const [cameraProductId, setCameraProductId] = useState<string | undefined>(undefined);

/**
 * Camera
 */
const {hasPermission, requestPermission} = useCameraPermission();
const device = useCameraDevice('back');

useEffect(() => {
    console.log(`Device variant${variant}`);
    (async () => {
        if (hasPermission) {
            console.log('📸 has camera permission');
        } else {
            await requestPermission();
        }
    })();
}, []);

/**
 * Scan barcode and setting up device registration
 * @param event
 */
const codeScanner = useCodeScanner({
    codeTypes: ['data-matrix'],
    onCodeScanned: async codes => {
        if (codes.length > 0 && codes[0].value) {
            if (
                codes[0].value.match('^[A-Z2-7]{10}$') !== null &&
                cameraProductId === undefined
            ) {
                setCameraProductId(codes[0].value);
                await setupDevice(codes[0].value, undefined);
            }
        }
    },
});

<Box style={styles.centerContainer}>
    {cameraStatus === 'active' &&
        (device ? (
            <Camera
                style={StyleSheet.absoluteFill}
                device={device}
                isActive={true}
                codeScanner={codeScanner}
                zoom={1.5}
            />
        ) : (
            <Box />
        ))}

    {cameraStatus === 'unknown' && (
        <Button
            title={t('registerDevice:step.first.button.camera')}
            iconName="camera"
            onPress={() => {
                setCameraStatus('active');
            }}
        />
    )}

    {cameraStatus === 'load' && <CameraActivityIndicator />}
</Box>

Relevant log output

As this issue happened in production. So, I don't have logs for it.

Camera Device

As this issue happened in production. So, I don't have logs for it.

Device

Google Pixel 7a

VisionCamera Version

3.5.1

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

mrousavy commented 2 weeks ago

This has been fixed in VisionCamera V4.