简体   繁体   中英

Fatal Execution Engine Error in Managed C# code

I have experienced Access Violation Exceptions and Fatal Execution Engine Error (it seems to be the same error) in managed code in C#. I have narrowed it down to the following snippet. Am I missing something? I thought it should not be possible to these kind of exceptions in managed code. I have seen it both in .net 4.7 and 4.5 and on multiple different computers? Is this a known issue in .Net?

    public static class FatalExecutionEngineBugExposer
{

    public static void Main(string[] args)
    {

        for (int i = 0; i < 500000; i++)
        {
            try
            {
                var testProblem = new TestProblem();
                testProblem.AddTrianglesExperiment();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetBaseException());
            }
        }
    }

    public class TestProblem
    {
        public struct Point
        {
            public double X, Y, Z;
        }

        public void AddTrianglesExperiment()
        {
            var points = new Point[28800];

            Parallel.ForEach(Partitioner.Create(0, points.Length),
                range =>
                {
                    // Create cache
                    var cache = new CubeRefCache();
                    cache.Entries = new CubeRefCacheEntry[20000];

                    // Add triangles
                    for (int i = range.Item1; i < range.Item2; i++)
                    {
                        ProcessTriangle(ref points[i].X, ref points[i].Y, ref points[i].Z, cache);  
                    }
                });
        }

        void ProcessTriangle(ref double pt1, ref double pt2, ref double pt3, CubeRefCache cache)
        {
            cache.Add(0, 0);
        }

        public struct CubeRefCacheEntry
        {
            public int Index;
            public int Item;
        }

        class CubeRefCache
        {
            internal CubeRefCacheEntry[] Entries;

            internal void Add(int index, int item)
            {
                Entries[0].Index = index;
                Entries[0].Item = item;
            }
        }
    }
}

This snippet "typically" fails within a minute.

UPDATE: It should probably be run in 64-bit. If compiled with 'Any CPU', the issue takes a lot longer to reproduce.

UPDATE2: usings I have:

usings

The original Github issue ( https://github.com/dotnet/corefx/issues/33157 ) has been closed as a duplicate of https://github.com/dotnet/coreclr/issues/20690 . Apparently, this is a known issue that has been fixed in .NET 4.8 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM