mmaitre314 / MediaCaptureWPF

Camera preview in WPF Desktop apps using WinRT MediaCapture
http://mmaitre314.github.io/MediaCaptureWPF
Apache License 2.0
52 stars 26 forks source link

COMException (E_NOINTERFACE) raised inside CapturePreviewNative when run inside Parallels Desktop #11

Open kitgrose opened 5 years ago

kitgrose commented 5 years ago

I am running Windows 10 Pro (v1809 build 17763.292) inside Parallels Desktop Pro (v14.1.0 (45387)) on macOS Mojave (v10.14.1 (18B75)). I have three cameras connected; one conventional USB webcam and the two integrated FaceTime cameras built into my displays, connected over Thunderbolt. All three cameras work fine in the built-in Windows Camera app.

When I run CaptureTestApp on this machine, I get the following managed exception:

System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=Exception has been thrown by the target of an invocation.
  Source=mscorlib
  StackTrace:
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at CaptureTestApp.App.Main()

Inner Exception 1:
COMException: Exception of type 'System.Runtime.InteropServices.COMException' was thrown.

I installed the debugging symbols to get the detail about the inner exception. It is reported as follows:

System.Runtime.InteropServices.COMException
  HResult=0x80004002
  Message=Exception of type 'System.Runtime.InteropServices.COMException' was thrown.
  Source=MediaCaptureWPF.Native
  StackTrace:
   at MediaCaptureWPF.Native.CapturePreviewNative.RefreshPreview() in c:\users\matthieu\source\repos\mediacapturewpf\mediacapturewpf.native\capturepreviewnative.cpp:line 126

Despite the stack trace indicating line 126, the debugger is broken on line 127:

CHK(buffer.QueryInterface(&bufferDxgi));

Note that I've loaded the NuGet version of MediaCaptureWPF into the CaptureTestApp project because I don't have the C++ SDKs installed on my machine. I'm not sure if that makes any difference in this case.

When I look up HResult 0x80004002 it's reported as E_NOINTERFACE.

As mentioned above, the cameras work fine in Microsoft's native Camera app, and also in a very basic UWP app with the following code:

var capture = new MediaCapture();
await capture.InitializeAsync(new MediaCaptureInitializationSettings
{
    StreamingCaptureMode = StreamingCaptureMode.Video
});

capturePreview.Source = capture;
await capture.StartPreviewAsync();

When I boot into Windows using Boot Camp, the cameras all work fine even inside MediaCaptureWPF, so I'm expecting this is going to be caused in some way by Parallels' Direct3D drivers (and I intend to raise this issue with them too), but since an uncaught exception is raised inside MediaCaptureWPF (and it doesn't happen when using the cameras inside UWP even inside Parallels), I figured I'd report it here too.

I'm happy to provide any extra detail or perform extra testing if need be to further diagnose this issue (it would be very helpful for me to be able to develop this app inside Parallels).

Tennyleaz commented 3 years ago

I also got COMException at MediaCaptureWPF.Native.CapturePreviewNative.RefreshPreview() exception, by building this project myself, and tested on a Windows 8.1 machine.