cureos / accord-samples

Sample applications using Portable AForge.NET and Accord.NET Frameworks
18 stars 8 forks source link

Run time error 'System.AccessViolationException' when trying to run the Face detection example. #1

Closed AndrewKaplanovsky closed 8 years ago

AndrewKaplanovsky commented 8 years ago

Hi,

When I try to run the face detection example, I get this error:

An unhandled exception of type 'System.AccessViolationException' occurred in Xamarin.Forms.Platform.WinRT.DLL

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

I tried to run the following solutions:

Both raise the same error.

Project FaceDetection, MainPage.xaml.cs, private void OnDetectButtonClicked(object sender, EventArgs args):

if (objects.Length > 0) { var marker = new RectanglesMarker(objects, Color.FromArgb(0xff, 0xff, 0x00, 0xff));

     var stream = new MemoryStream();
     marker.Apply(this.bitmap).Save(stream, ImageFormat.Jpeg); <---- Here I check the stream in debug mode, and it is empty after saving the image into it

     this.ImageView.Source = this.GetImageSourceFromStream(stream);

}

Regards, Andrew Kaplanovsky

anders9ustafsson commented 8 years ago

@AndrewKaplanovsky Which versions of the Accord, Shim and Shim.Drawing libraries are you using? It's been a while since I updated the references in these projects, this might play a role.

I will look closer into this issue when time permits.

AndrewKaplanovsky commented 8 years ago

Hi Anders,

In the app I'm developing: Accord 3.0.2.60302 Shim 2.2.0 Shim.Drawing 3.0.0

In accord-samples that I downloaded from GH, FaceDetection: Accord 3.0.2.50804 Shim 1.0.2.50909 Shim.Drawing 2.2.5.50526

In both cases I get the same error:

When I create a new Stream, I see that its length is zero

1 - new stream

After the Bitmap is saved into the stream, its length is still zero

2 - after the bitmaps was saved to the memory stream

After that the app fails with the 'System.AccessViolationException' trying to display the processed image.

Thank you, Andrew

anders9ustafsson commented 8 years ago

OK, I have looked a little closer into this issue, and it seems like there is a problem with Bitmap.Save for the Universal (8.1) platform. I will attempt a bug fix as soon as possible. In the mean time, many thanks for reporting, @AndrewKaplanovsky !

AndrewKaplanovsky commented 8 years ago

@anders9ustafsson, thank you so much for your help! I'll wait for the fix.

anders9ustafsson commented 8 years ago

@AndrewKaplanovsky I have implemented a fix and verified that it works. In a short while I will publish a new Shim.Drawing release with the bug fix included.

AndrewKaplanovsky commented 8 years ago

@anders9ustafsson, thank you very much!

AndrewKaplanovsky commented 8 years ago

@anders9ustafsson Hi Anders, sorry for disturbing you, but when it is possible to expect the fixed version of the Shim.Drawing dll for the Universal platform published?

anders9ustafsson commented 8 years ago

@AndrewKaplanovsky I am sorry about the delay, quite a few things have gotten in the way. I'll see what I can do within the next couple of days, but I am afraid I cannot promise anything for sure.

anders9ustafsson commented 8 years ago

@AndrewKaplanovsky I have now published version 3.0.1 of Shim.Drawing on NuGet, with the fix for Image.Save on Windows Universal. Please give it a try and see if it works sufficiently for you.

AndrewKaplanovsky commented 8 years ago

Anders, thank you very much, it works now!