Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 v4.0.0-beta.13 - Camera.onError(unknown/unknown): already bound to a different lifecycle. #2721

Closed
3 of 5 tasks
isinuyk opened this issue Apr 6, 2024 · 5 comments
Closed
3 of 5 tasks
Labels
馃悰 bug Something isn't working

Comments

@isinuyk
Copy link

isinuyk commented Apr 6, 2024

What's happening?

I wanted to flip the camera from the Back to the Front or the vice versa but got this error: Camera.onError(unknown/unknown): Use case Preview:androidx.camera.core.Preview-de4f3173-e76f-49cf-b589-73fab23b84b1 already bound to a different lifecycle.

2024-04-06_22-45-21_Edited.mp4

FYI: the bug isn't reproducible on the latest stable version 3.9.2. So it is a bug only for v4.

Reproduceable Code

export default function App() {
  const [view, setView] = useState<'front' | 'back'>('back');
  const device = useCameraDevice(view);

  const {hasPermission, requestPermission} = useCameraPermission();
  console.log(JSON.stringify(device, (k, v) => (k === 'formats' ? [] : v), 2));
  useEffect(() => {
    requestPermission();
  }, []);

  if (!hasPermission || !device) {
    return null;
  }
  return (
    <>
      <Camera style={StyleSheet.absoluteFill} device={device} isActive={true} />
      <TouchableOpacity
        onPress={() => setView(prev => (prev === 'back' ? 'front' : 'back'))}
        style={{
          position: 'absolute',
          bottom: 20,
          borderWidth: 2,
          borderColor: 'white',
          backgroundColor: 'transparent',
          right: 20,
          width: 40,
          height: 40,
          borderRadius: 20,
        }}
      />
    </>
  );
}

Relevant log output

Failed to configure CameraSession! Error: Use case Preview:androidx.camera.core.Preview-de4f3173-e76f-49cf-b589-73fab23b84b1 already bound to a different lifecycle., Config-Diff: Difference(deviceChanged=true, outputsChanged=false, sidePropsChanged=false, isActiveChanged=false, locationChanged=false)
java.lang.IllegalStateException: Use case Preview:androidx.camera.core.Preview-de4f3173-e76f-49cf-b589-73fab23b84b1 already bound to a different lifecycle.
	at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:587)
	at androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:386)
	at com.mrousavy.camera.core.CameraSession.configureCamera(CameraSession.kt:417)
	at com.mrousavy.camera.core.CameraSession.configure(CameraSession.kt:165)
	at com.mrousavy.camera.CameraView$update$1.invokeSuspend(CameraView.kt:156)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:226)
	at android.os.Looper.loop(Looper.java:313)
	at android.app.ActivityThread.main(ActivityThread.java:8669)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

'Camera.onError(unknown/unknown): Use case Preview:androidx.camera.core.Preview-de4f3173-e76f-49cf-b589-73fab23b84b1 already bound to a different lifecycle.', { [unknown/unknown: Use case Preview:androidx.camera.core.Preview-de4f3173-e76f-49cf-b589-73fab23b84b1 already bound to a different lifecycle.]
  name: 'unknown/unknown',
  _code: 'unknown/unknown',
  _message: 'Use case Preview:androidx.camera.core.Preview-de4f3173-e76f-49cf-b589-73fab23b84b1 already bound to a different lifecycle.',
  _cause: 
   { stacktrace: 'java.lang.IllegalStateException: Use case Preview:androidx.camera.core.Preview-de4f3173-e76f-49cf-b589-73fab23b84b1 already bound to a different lifecycle.\n\tat androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:587)\n\tat androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle(ProcessCameraProvider.java:386)\n\tat com.mrousavy.camera.core.CameraSession.configureCamera(CameraSession.kt:417)\n\tat com.mrousavy.camera.core.CameraSession.configure(CameraSession.kt:165)\n\tat com.mrousavy.camera.CameraView$update$1.invokeSuspend(CameraView.kt:156)\n\tat kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)\n\tat kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)\n\tat android.os.Handler.handleCallback(Handler.java:938)\n\tat android.os.Handler.dispatchMessage(Handler.java:99)\n\tat android.os.Looper.loopOnce(Looper.java:226)\n\tat android.os.Looper.loop(Looper.java:313)\n\tat android.app.ActivityThread.main(ActivityThread.java:8669)\n\tat java.lang.reflect.Method.invoke(Native Method)\n\tat com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)\n\tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)\n',
     message: 'Use case Preview:androidx.camera.core.Preview-de4f3173-e76f-49cf-b589-73fab23b84b1 already bound to a different lifecycle.' } }

Camera Device

{
  "hardwareLevel": "full",
  "minExposure": -20,
  "neutralZoom": 1,
  "minZoom": 1,
  "supportsFocus": true,
  "formats": [],
  "supportsLowLightBoost": false,
  "hasTorch": false,
  "supportsRawCapture": false,
  "minFocusDistance": 0,
  "sensorOrientation": "landscape-right",
  "maxZoom": 8,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "isMultiCam": false,
  "position": "front",
  "id": "1",
  "hasFlash": false,
  "maxExposure": 20,
  "name": "1 (FRONT) androidx.camera.camera2"
}

Device

Samsung Galaxy A11

VisionCamera Version

v4.0.0-beta.13

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

@isinuyk isinuyk added the 馃悰 bug Something isn't working label Apr 6, 2024
@Aycom366
Copy link

Aycom366 commented Apr 9, 2024

have you found a fix for this @isinuyk ?

@bexelstudio
Copy link

have the same issue on A9 Samsung no ref found. on 3.9.2 black screen!

@moafandi0
Copy link

having the same issue on OnePlus5

@moafandi0
Copy link

The camera component needs to be unmounted before you can change the camera. Here's a workaround for now:

const [cameraPosition, setCameraPosition] = useState("front");
const [isActive, setIsActive] = useState(true);
let device = useCameraDevice(cameraPosition);
const onFlipCameraPressed = useCallback(() => {
    setIsActive(false);
  }, [isActive]);
useEffect(() => {
    if (!isActive) {
      cameraPosition === "front"
        ? setCameraPosition("back")
        : setCameraPosition("front");
      setIsActive(true);
    }
    return () => {};
  }, [isActive]);

and add isActive to conditionally render the component:

{isActive && (
        <Camera
          style={{ flex: 1 }}
          device={device}
          isActive={true}
        />
      )}

@mrousavy
Copy link
Owner

Fixed this issue in #2768. 馃挭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃悰 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants