I'm working with augmented reality app and I want to draw a line that connects two movable objects on top of the camera. However I get this exception
Process: test.job.reality.augument.job.com.augumentrealitytest, PID: 15056 java.lang.IllegalArgumentException at android.view.Surface.nativeLockCanvas(Native Method) at android.view.Surface.lockCanvas(Surface.java:266) at custom.MyCameraView$MyThread.run(MyCameraView.java:447) Here's my code as you can see I start my thread in surfaceCreted method. I'm thinking that I can't lockCanvas because it's a;ready locked by camera, am I right? However I to draw line is it possible (I'm using beyondAR augumented reality library)
public class MyCameraView extends SurfaceView implements SurfaceHolder.Callback, Camera.PictureCallback { private MyThread thread; public MyCameraView(Context context, AttributeSet attrs) { super(context, attrs); init(context); } @SuppressWarnings("deprecation") private void init(Context context) { mIsPreviewing = false; mHolder = getHolder(); mHolder.addCallback(this); configureCamera(); if (Build.VERSION.SDK_INT <= 10) {// Android 2.3.x or lower mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } thread=new MyThread(getHolder(),this); getHolder().addCallback(this); setFocusable(true); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); } public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, acquire the camera and tell it where // to draw. thread.startrun(true); thread.start(); try { if (mCamera == null) { init(getContext()); if (mCamera == null) { return; } } mCamera.setPreviewDisplay(holder); } catch (IOException exception) { if (mCamera != null) { mCamera.release(); } mCamera = null; Logger.e(TAG, "CameraView -- ERROR en SurfaceCreated", exception); } } public void surfaceDestroyed(SurfaceHolder holder) { releaseCamera(); thread.startrun(false); thread.stop(); } public class MyThread extends Thread{ private SurfaceHolder msurfaceHolder; private MyCameraView mSurfaceView; private boolean mrun =false; public MyThread(SurfaceHolder holder, MyCameraView mSurfaceView) { this.msurfaceHolder = holder; this.mSurfaceView=mSurfaceView; } public void startrun(boolean run) { mrun=run; } @SuppressLint("WrongCall") @Override public void run() { super.run(); Canvas canvas; while (mrun) { canvas=null; try { canvas = msurfaceHolder.lockCanvas(); synchronized (msurfaceHolder) { mSurfaceView.onDraw(canvas); } } finally { if (canvas != null) { msurfaceHolder.unlockCanvasAndPost(canvas); } } } } }