Skip to content

System.AccessViolationException applying ColorSpace #336

@programatix

Description

@programatix

Description

I'm using Magick.NET with AForge.Video.DirectShow in its NewFrame event (http://www.aforgenet.com/framework/docs/html/0592d628-6d09-b601-1b72-d04f55fc748f.htm). It triggered the exception when I tried to change the ColorSpace to gray. It has no issue with Rotate, Crop, ContracstStretch and Normalize.

Steps to Reproduce

The following is the code snippet

        private void CameraNewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            var newFrame = eventArgs.Frame.Clone() as System.Drawing.Bitmap;

            Dispatcher.Invoke(() =>
            {
                ImageMagick.IMagickImage image = new ImageMagick.MagickImage(newFrame);
                image.ColorSpace = ImageMagick.ColorSpace.Gray; // exception occurs
            });
        }

The following is the exception

"System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at ImageMagick.MagickImage.NativeMethods.X86.MagickImage_ColorSpace_Set(IntPtr instance, UIntPtr value, IntPtr& exception)
   at ImageMagick.MagickImage.NativeMagickImage.set_ColorSpace(ColorSpace value)
   at ImageMagick.MagickImage.set_ColorSpace(ColorSpace value)
   at xxx.MyWebCam.<>c__DisplayClass43_0.<CameraNewFrame>b__1() in MyWebCam.xaml.cs:line xxx
   at System.Windows.Threading.DispatcherOperation.InvokeDelegateCore()
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   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.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at xxx.Main()"

System Configuration

  • Magick.NET version: Magick.NET-Q8-AnyCPU 7.8.0
  • Environment (Operating system, version and so on):
    • Windows 10.0.17763.55
    • .NetFramework 4.7.2
  • Additional information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions