question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.AccessViolationException applying ColorSpace

See original GitHub issue

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:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
programatixcommented, Oct 15, 2018

From the other thread (https://github.com/dlemstra/Magick.NET/issues/199), I tried setting ImageMagick.OpenCL.IsEnabled = false and it doesn’t crash anymore. I’m not using NVIDIA GPU though. It’s Intel HD Graphics 630. Would I be losing anything from setting OpenCL to false?

I’ll try to reproduce this issue without AForge, but I doubt I can manage, since it seems to me like the crash happened inside an event (where the handler is in the main EXE) called by a different DLL?

0reactions
dlemstracommented, Oct 20, 2018

Most likely a drivers issue then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

shrink image c++ - 'System.AccessViolationException'
This error occurs because you are accessing outside of memory allocated for an array. There are several places in your code where this...
Read more >
AccessViolationException Class (System)
An access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been...
Read more >
Debugging System.AccessViolationException - DllImport hell
The exception typically happens when unmanaged code tries to read or write from/to memory that hasn't been allocated yet. Debugging System.
Read more >
Color Management in Adobe After Effects - YouTube
00:35 What is Color Management 01:33 Color Spaces 02:57 ... Messages 5:17 Common Color Spaces 7:56 Practical Application in After Effects If ...
Read more >
[Help] Every .NET application crashes ...
NET application was crashing on my computer. Most of the apps open for a brief second and close ... AccessViolationException at System.Net.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found