我在可写位图上渲染视频帧,一段时间后应用程序随机崩溃,正在监视内存和 cpu 负载看起来不错
帧被抓取并排队等待从线程池线程渲染,并在调度程序上调用以下代码
this.Dispatcher.Invoke((Action)(() =>
{
BitmapData dataRE = rData.Frame.Bitmap.LockBits(new Rectangle(0, 0, rData.Frame.Bitmap.Width, rData.Frame.Bitmap.Height), ImageLockMode.ReadWrite, rData.Frame.Bitmap.PixelFormat);
rightEyeWB.Lock();
rightEyeWB.WritePixels(new Int32Rect(0, 0, rData.Frame.Bitmap.Width, rData.Frame.Bitmap.Height), dataRE.Scan0, rData.Frame.Bitmap.Width * rData.Frame.Bitmap.Height, dataRE.Stride);
rightEyeWB.Unlock();
}), DispatcherPriority.Send);
rData.Frame.Dispose();
当我检查 Windows 日志以获取崩溃报告时,我得到了以下跟踪
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
at System.Windows.Media.MILUtilities.MILCopyPixelBuffer(Byte*, UInt32, UInt32, UInt32, Byte*, UInt32, UInt32, UInt32, UInt32, UInt32)
at System.Windows.Media.Imaging.WriteableBitmap.WritePixelsImpl(System.Windows.Int32Rect, IntPtr, Int32, Int32, Int32, Int32, Boolean)
at System.Windows.Media.Imaging.WriteableBitmap.WritePixels(System.Windows.Int32Rect, IntPtr, Int32, Int32)
at Cyclops.View.CameraWindow.renderPupilFrames()
at Cyclops.View.CameraWindow.<grabFrames>b__11()
at System.Windows.Threading.DispatcherOperation.InvokeDelegateCore()
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)