[Android Q&A, Help & Troubleshooting] camdenmil:
I have been running the CM12.1 nightlies on an HTC Droid DNA for a while and several months ago, any app that uses the camera started throwing "can't connect to the camera" errors and subsequently crashing. I've flashed various ROMs thinking that it was a issue with the nightly but I've gotten the same results with all the CM releases back to CM11. I have wiped before every ROM flash.

After a reboot, the camera app successfully connects to the camera and displays camera output so I do not believe it's a hardware problem. When I try to take a picture, the app hangs and I have to force close it. Any subsequent re-openings of the camera app just throw a "Can't connect to the camera" error. This seems to be a software issue but I can't figure out why I'm having this issue with clean flashes of ROMs that have worked fine in the past. I have tried putting my device back into factory configuration (S-ON, stock boot, recovery, radio, ROM, etc) and still get the same errors with the camera.

Here's logcat output if that means anything. The WindowLeaked and the following stack trace occurs after dismissing the "can't connect to the camera" dialog.

W/CameraService( 242): CameraService::connect X (pid 3484) rejected (existing client).
W/CameraBase( 3484): An error occurred while connecting to camera: 0
E/CameraHolder( 3484): fail to connect Camera:-1, aborting.
E/CAM_PhotoModule( 3484): Failed to open camera:0
E/AwesomePlayer( 242): LPAPlayer::Clip duration setting of less than 30sec not supported, defaulting to 60sec
W/AwesomePlayer( 242): Trying to create tunnel player mIsTunnelAudio 0, LPAPlayer::mObjectsAlive 0, TunnelPlayer::mTunnelObjectsAlive = 0, (mAudioPlayer == NULL) 1
E/AwesomePlayer( 242): LPAPlayer::Clip duration setting of less than 30sec not supported, defaulting to 60sec
W/InputMethodManagerService( 583): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@42094c98 attribute=null, token = android.os.BinderProxy@42262f20
W/CAM_UI ( 3484): SurfaceTexture destroyed
E/WindowManager( 3484):
E/WindowManager( 3484): android.view.WindowLeaked: Activity com.android.camera.CameraActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4211fa88 V.E..... R....... 0,0-1026,584} that was originally added here
E/WindowManager( 3484):	at android.view.ViewRootImpl.<init>(ViewRootImpl.java:346)
E/WindowManager( 3484):	at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
E/WindowManager( 3484):	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
E/WindowManager( 3484):	at android.app.Dialog.show(Dialog.java:286)
E/WindowManager( 3484):	at android.app.AlertDialog$Builder.show(AlertDialog.java:951)
E/WindowManager( 3484):	at com.android.camera.util.CameraUtil.showErrorAndFinish(CameraUtil.java:490)
E/WindowManager( 3484):	at com.android.camera.CameraActivity$2.onDeviceOpenFailure(CameraActivity.java:258)
E/WindowManager( 3484):	at com.android.camera.AndroidCameraManagerImpl$CameraOpenErrorCallbackForward$2.run(AndroidCameraManagerImpl.java:942)
E/WindowManager( 3484):	at android.os.Handler.handleCallback(Handler.java:733)
E/WindowManager( 3484):	at android.os.Handler.dispatchMessage(Handler.java:95)
E/WindowManager( 3484):	at android.os.Looper.loop(Looper.java:136)
E/WindowManager( 3484):	at android.app.ActivityThread.main(ActivityThread.java:5146)
E/WindowManager( 3484):	at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager( 3484):	at java.lang.reflect.Method.invoke(Method.java:515)
E/WindowManager( 3484):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
E/WindowManager( 3484):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
E/WindowManager( 3484):	at dalvik.system.NativeStart.main(Native Method)