© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•7mo ago•
2 replies
Nacho Man Randy Cabbage

System.ExecutionEngineException with WriteableBitmap

Looking at a project where GStreamer is being used to constantly update an <Image>. There is an
AppSink
AppSink
with a
.NewSample
.NewSample
event which is used to update the image. Now, the
<Image>
<Image>
element is hosted in a child window. Everything works fine until that child window is closed, and then the exception occurs inside of
Buffer.cs
Buffer.cs
in this method:

[MethodImpl(MethodImplOptions.NoInlining)]
private unsafe static void _Memmove(ref byte dest, ref byte src, nuint len)
{
    fixed (byte* dest2 = &dest)
    {
        fixed (byte* src2 = &src)
        {
            __Memmove(dest2, src2, len); // error here
        }
    }
}
[MethodImpl(MethodImplOptions.NoInlining)]
private unsafe static void _Memmove(ref byte dest, ref byte src, nuint len)
{
    fixed (byte* dest2 = &dest)
    {
        fixed (byte* src2 = &src)
        {
            __Memmove(dest2, src2, len); // error here
        }
    }
}


here's relevant bitmap code
appSink.NewSample += Update;

public void Update(object sender, NewSampleArgs args)
{
    var sink = (Gst.App.AppSink)sender;

    using var sample = sink?.PullSample();
    if (sample == null) return;

    using var buffer = sample?.Buffer;
    if (buffer == null) return;

    MapInfo map;
    if (!buffer.Map(out map, MapFlags.Read)) return;

    if (!_cts.Token.IsCancellationRequested && !_window.Dispatcher.HasShutdownStarted
                                            && !_window.Dispatcher.HasShutdownFinished)
    {
        // _window is the window hosting the <Image>
        _window.Dispatcher.BeginInvoke(() =>
        {
            _imageSource.WritePixels(rect, buffer, stride, 0, 0); // error here after _window closes
            // _imageSource is the <Image>'s Source
        });
    }

    buffer.Unmap(map);
}

public void Stop()
{
    _cts.Cancel();
}
appSink.NewSample += Update;

public void Update(object sender, NewSampleArgs args)
{
    var sink = (Gst.App.AppSink)sender;

    using var sample = sink?.PullSample();
    if (sample == null) return;

    using var buffer = sample?.Buffer;
    if (buffer == null) return;

    MapInfo map;
    if (!buffer.Map(out map, MapFlags.Read)) return;

    if (!_cts.Token.IsCancellationRequested && !_window.Dispatcher.HasShutdownStarted
                                            && !_window.Dispatcher.HasShutdownFinished)
    {
        // _window is the window hosting the <Image>
        _window.Dispatcher.BeginInvoke(() =>
        {
            _imageSource.WritePixels(rect, buffer, stride, 0, 0); // error here after _window closes
            // _imageSource is the <Image>'s Source
        });
    }

    buffer.Unmap(map);
}

public void Stop()
{
    _cts.Cancel();
}


In the windows' OnClosed event:
protected override void OnClosed(EventArgs e)
{
    _videoHelper.Stop();
    base.OnClosed(e);
}
protected override void OnClosed(EventArgs e)
{
    _videoHelper.Stop();
    base.OnClosed(e);
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ 'System.ExecutionEngineException' occurred in WindowsBase.dll
C#CC# / help
3y ago
❔ Refresh WriteableBitmap
C#CC# / help
3y ago
Replacing A Specific Colour of A WriteableBitmap [Answered]
C#CC# / help
4y ago
Help with license system
C#CC# / help
10mo ago