dlazaro66 / QRCodeReaderView

Modification of ZXING Barcode Scanner project for easy Android QR-Code detection and AR purposes
1.9k stars 491 forks source link

StartPreview Failed on Genymotion emulator #117

Closed codemaster730 closed 7 years ago

codemaster730 commented 7 years ago

Hi there,

I think this a kind of great library which is obviously better than others. But it has serious crash issue . First time it seemed working fine. But when after it scanned the code and I went to other activities and came back , it was crashed every time.

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.payyus.app, PID: 27792 java.lang.RuntimeException: startPreview failed at android.hardware.Camera.startPreview(Native Method) at com.google.zxing.client.android.camera.CameraManager.startPreview(CameraManager.java:202) at com.dlazaro66.qrcodereaderview.QRCodeReaderView.surfaceChanged(QRCodeReaderView.java:250) at android.view.SurfaceView.updateWindow(SurfaceView.java:583) at android.view.SurfaceView.access$000(SurfaceView.java:86) at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:175) at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1867) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)

I am using genymotion emulator (Android 4.4.4) and my webcamera.

codemaster730 commented 7 years ago

This crash even happens on the SampleCode.

codemaster730 commented 7 years ago

How are others getting along with this library? Sample code is also broken. Always making crashes... Am I the only one who got this crashed?

codemaster730 commented 7 years ago

I think the problem is on this method. I tried to set device orientation manually but still no luck.

@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Log.d(TAG, "surfaceChanged");

if (holder.getSurface() == null) {
  Log.e(TAG, "Error: preview surface does not exist");
  return;
}

if (mCameraManager.getPreviewSize() == null) {
  Log.e(TAG, "Error: preview size does not exist");
  return;
}

mPreviewWidth = mCameraManager.getPreviewSize().x;
mPreviewHeight = mCameraManager.getPreviewSize().y;

mCameraManager.stopPreview();

// Fix the camera sensor rotation
mCameraManager.setPreviewCallback(this);
mCameraManager.setDisplayOrientation(getCameraDisplayOrientation());

mCameraManager.startPreview();

}

dlazaro66 commented 7 years ago

@axiom88-guru I don't think it's a permission problem as other​ people faced. I sometimes had problems using the genymotion emulator and the camera. Can you please restart the emulator or even create a new one and try again? Is the same problem happening on a real device?

codemaster730 commented 7 years ago

hi David, I created new virtual devices(with android7.0 phone and android 4.4 tablet) but they all crashed. I downloaded your sample code of course and made it run on my local machine. Please check these screenshots below. One is the video shots which can make you clear.

https://drive.google.com/open?id=0B_MGEpNLhIM0cENtcTF6ZFBWTkE https://drive.google.com/open?id=0B_MGEpNLhIM0cFVZUG10d2kxc0U https://drive.google.com/open?id=0B_MGEpNLhIM0Tzc4UGFudmNNaGM

that is the problem that i couldn't handle why it crashes sometimes, and it don't sometimes . *I also made your sample source run on my LG android phone and it works well without any crashes.

Any idea with this ? Thanks in advance.

codemaster730 commented 7 years ago

Did work well on physical devices.