C# AccessViolationException


#1

Hi

I’m trying to use the PhotoDetector, but when I create a Frame-object I’m getting an AccessViolationException in Affdex.dll. Here’s the code I’m using:
Image img = Image.FromFile(path);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Frame frame = new Frame(img.Width, img.Height, ms.ToArray(), Frame.COLOR_FORMAT.RGB); detector.start();
detector.process(frame);

And here’s my output when debugging:
‘AffectivaTest3.exe’ (CLR v4.0.30319: DefaultDomain): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: DefaultDomain): Loaded ‘C:\Users\RKW-PostGrad\Documents_meesters\projek\AffectivaTest3\AffectivaTest3\bin\Debug\AffectivaTest3.exe’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\WindowsBase\v4.0_4.0.0.0__31bf3856ad364e35\WindowsBase.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_64\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xaml\v4.0_4.0.0.0__b77a5c561934e089\System.Xaml.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Remote Debugger\x64\Runtime\Microsoft.VisualStudio.Debugger.Runtime.dll’.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll’. Symbols loaded.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework.Aero2\v4.0_4.0.0.0__31bf3856ad364e35\PresentationFramework.Aero2.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\PresentationFramework-SystemXml\v4.0_4.0.0.0__b77a5c561934e089\PresentationFramework-SystemXml.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\Users\RKW-PO~1\AppData\Local\Temp\VisualStudio.XamlDiagnostics.9536\Microsoft.VisualStudio.DesignTools.WpfTap.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\SMDiagnostics\v4.0_4.0.0.0__b77a5c561934e089\SMDiagnostics.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Internals\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Internals.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\UIAutomationTypes\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationTypes.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\UIAutomationProvider\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationProvider.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\Users\RKW-PostGrad\Documents_meesters\projek\AffectivaTest3\AffectivaTest3\bin\Debug\Affdex.dll’. Cannot find or open the PDB file.
‘AffectivaTest3.exe’ (CLR v4.0.30319: AffectivaTest3.exe): Loaded ‘C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll’. Symbols loaded.
Exception thrown: ‘System.AccessViolationException’ in Affdex.dll
The program ‘[9536] AffectivaTest3.exe’ has exited with code -1073741819 (0xc0000005) ‘Access violation’.

Is my code correct? Please help?

Thanks


Problems creating a Frame for Photodetector
#2

Which line of code produces the exception? Can you show the stack trace?


#3

Hi

The line is: Frame frame = new Frame(img.Width, img.Height, ms.ToArray(), Frame.COLOR_FORMAT.RGB);

The stack trace: at affdex.Frame.{ctor}(Frame* , Int32 , Int32 , Void* , COLOR_FORMAT , Single )
at Affdex.Frame…ctor(Int32 frameWidth, Int32 frameHeight, Byte[] pixels, COLOR_FORMAT frameColorFormat, Single timestamp)

I also found that this only happens when I use a picture that contains a face. If there’s no face it continues fine.

Thanks


#4

Looks like you are passing some bad input params to the Frame constructor. Check the values for img and ms in the debugger. I suspect that maybe img.Width and/or img.Height do not match the size of ms.ToArray().