System.AccessViolationException on rendering frame on WritableBitmap

418 Views Asked by At

I am rendering video frames on writable bitmap, and application crashing randomly after sometime, am monitoring memory and cpu load looks fine

Frames are grabbed and queued for rendering from threadpool thread and am invoking following code on dispatcher

    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();

and when I check windows log for crash report I got following trace

   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)
0

There are 0 best solutions below