Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScaleDecodedVideoFrame Throws Exception: attempted to read or write protected memory #106

Open
panzhic039 opened this issue Mar 7, 2021 · 2 comments

Comments

@panzhic039
Copy link

panzhic039 commented Mar 7, 2021

Hello Bogdanov,

Thanks for this amazing c# library. It works well for me overall. However, sometimes this ScaleDecodedVideoFrame method will throw the attempted to read or write protected memory exception. What went wrong here and how should I handle it? It is a very rare exception, but it did crash my program and the try catch block doesn't seem to catch it after all.

The original call is from the TransformTo(IntPtr buffer, int bufferStride, TransformParameters parameters) method in FFmpegVideoDecoder.cs

int resultCode = FFmpegVideoPInvoke.ScaleDecodedVideoFrame(_decoderHandle, videoScaler.Handle, buffer, bufferStride);

[DllImport(LibraryName, EntryPoint = "scale_decoded_video_frame", CallingConvention = CallingConvention.Cdecl)]
public static extern int ScaleDecodedVideoFrame(IntPtr handle, IntPtr scalerHandle, IntPtr scaledBuffer, int scaledBufferStride);

Thank you so much for the answer!

@panzhic039
Copy link
Author

Problem solved, with this solution, able to catch the exception. However it is still beneficial to know the root reason causing this!

The reason being that the exception happens outside the memory reserved by CLR. It happens within the unmanaged C++ code.

Here is the link for the solution to catch the exception:
https://airbrake.io/blog/dotnet-exception-handling/system-accessviolationexception

Hope this saves someone's day.

@cactusjack66
Copy link

Did you find any further solution to this?
I have the same problem with the decode function. Sometimes it throws an AccessViolationException. I dont know why.
As I am developing under .net core I cannot use your solution, it might be better to fix it in the c++ library helper, but that goes beyond my knowledge...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants