I have a camera class, in this class I used a timer and in my tick event I save a video using AForge.NetVideoFileWriter in C ++ / Cli (x86, .net framework: v4.6).
This should not happen as it is managed code. But even if I complete the try catch block, the program crashes because of AccessViolationException. I checked that the image is not zero. Something related to VideoFileWriter. This happens at any time between application startup up to 30 minutes of work.
An unhandled exception of type "System.AccessViolationException" occurred in AForge.Video.FFMPEG.dll Additional information: Attempted to read or write protected memory. This often indicates that another memory is corrupted.
In Visual Studio output, I see
An exception was thrown at 0x0C4D689F (swscale-2.dll) in the test.exe file: 0xC0000005: location of the access violation record 0x09F83D80. Exception: "System.AccessViolationException" in AForge.Video.FFMPEG.dll
the code:
private: System::Void Video_Recorder_Tick(System::Object^ sender, System::Timers::ElapsedEventArgs^ e)
{
Bitmap^ save = ConvertMatToBitmap(image);
if(writer!= nullptr)
writer->WriteVideoFrame(save);
delete save;
}
VideoFileWriter ^writer = gcnew VideoFileWriter();
private: Void load_VideoWriter()
{
writer->Open("C:/video.avi", 640, 480, 10, VideoCodec::Default);
}
Visual Studio showed several values for writer
BitRate 400000
Codec Default
FrameRate 10
Height 480
IsOpen true
Width 640
Let me know if anyone needs more information.
the call stack didn't help much

To my surprise, no one on the Internet has this problem!
The code seems straightforward, what could be the problem?
source
share