System.AccessViolationException from SimpleRtspPlayer example
See original GitHub issueDescribe the bug A unhandled AccessViolation exception which occurs when disconnecting (see reproduction steps). I’ve noticed this same issue in my own project, which uses the decoding implementation from SimpleRtspPlayer, and have been able to reproduce it in a fork of RtspClientSharp. However it is much more observable in my (closed-source) project then the RtspClientSharp fork, and often causes a crash on a single disconnect from the server. To observe more details I enabled native code debugging and found a error in avcodec-58.dll, so I am not sure if this is specific to this project or FFMPEG.
To Reproduce Steps to reproduce the behavior:
- Setup a RTSP server to connect to.
- Setup clone/fork of RtspClientSharp locally in Visual Studio. (I also made some adjustments for mine to build, though not sure if its relevant to this issue, see Additional context)
- Build and run SimpleRtspPlayer example in debug mode (using x86).
- Enter in RTSP server address setup from Step 1 and connect.
- Disconnect from the server and reconnect shortly afterwards (sometimes only a disconnect is required).
- Continue step 5 until a exception occurs.
Expected behavior I expect there to likely be issues when disconnecting/reconnecting too quickly (e.g. if a object is disposed or still exists), however from my experience it also occurs sometimes on a single disconnect (though I’ve only seen this in my program so far). Ideally the cause of the exception would be fixed, or at least not cause a crash.
Screenshots
First Exception (only when native debugging is on for SimpleRtspPlayer):
Exception thrown at 0x79B45CA0 (avcodec-58.dll) in CrawlerRTSPClient.exe: 0xC0000005: Access violation reading location 0x00001602.
Exception:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
stacktrace below:
Stacktrace
at SimpleRtspPlayer.RawFramesDecoding.FFmpeg.FFmpegVideoDecoder.TryDecode(RawVideoFrame rawVideoFrame) in C:\Users\DirectoryToProject\rtspclientsharp\Examples\SimpleRtspPlayer\RawFramesDecoding\FFmpeg\FFmpegVideoDecoder.cs:line 75
at SimpleRtspPlayer.GUI.RealtimeVideoSource.OnFrameReceived(Object sender, RawFrame rawFrame) in C:\Users\DirectoryToProject\rtspclientsharp\Examples\SimpleRtspPlayer\GUI\RealtimeVideoSource.cs:line 60
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at RtspClientSharp.Rtsp.RtspClientInternal.OnFrameGeneratedThreadSafe(RawFrame frame)
at RtspClientSharp.MediaParsers.H264Parser.TryGenerateFrame(ArraySegment`1 frameBytes)
at RtspClientSharp.MediaParsers.H264Parser.TryGenerateFrame()
at RtspClientSharp.MediaParsers.H264Parser.Parse(ArraySegment`1 byteSegment, Boolean generateFrame)
at RtspClientSharp.MediaParsers.H264VideoPayloadParser.ParseFU(ArraySegment`1 byteSegment, Int32 donFieldSize, Boolean markerBit)
at RtspClientSharp.MediaParsers.H264VideoPayloadParser.Parse(TimeSpan timeOffset, ArraySegment`1 byteSegment, Boolean markerBit)
at RtspClientSharp.Rtp.RtpStream.ProcessImmediately(RtpPacket& rtpPacket)
at RtspClientSharp.Rtp.RtpSequenceAssembler.ProcessPacket(RtpPacket& rtpPacket)
at RtspClientSharp.Rtsp.RtspClientInternal.<ReceiveRtpFromUdpAsync>d__36.MoveNext()
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.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c__DisplayClass4_0.<OutputAsyncCausalityEvents>b__0()
at System.Runtime.CompilerServices.TaskAwaiter.<>c__DisplayClass11_0.<OutputWaitEtwEvents>b__0()
at System.Threading.Tasks.AwaitTaskContinuation.ExecuteWorkItemHelper()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
Desktop (please complete the following information):
- OS: Windows 10
- IDE: Microsoft Visual Studio 2017 (latest)
- Version: ‘Modified’ (see below) v1.3.3 RtspClientSharp
Additional context Not sure if this is too relevant, here are some details on some adjustments I made to the project for my environment: In order to build with my environment I found I needed to adjust the libffmeghelper’s WindowsTargetPlatformVersion to 10.0.15063.0 (to use the default SDK). I also changed the SimpleRtspClient’s supported runTime and target framework version to v4.6.1. I am intending to use a UDP connection.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
@MysticMight I added your fix to my own project - so far everything works fine. Speaking of this file - do you think it may have sense to protect _scalersMap as well? In my code I am also locking _scalersMap, because TransformTo may attempt to add scaler while DropAllVideoScalers will be doing “foreach”.
@MysticMight I did it in a pretty simple way I also never have problems with Scaler, and anyway in my project TransformTo is redundant since I leave it to WPF control to adjust image. I just read your comment and remembered about this small thing. May be you can do it better. My own pull request is also waiting for author review, but I don’t want to mix unrelated things.