繁体   English   中英

托管C#代码中的致命执行引擎错误

[英]Fatal Execution Engine Error in Managed C# code

我在C#中的托管代码中遇到过访问冲突异常和致命执行引擎错误(似乎是同一个错误)。 我已将其缩小到以下代码段。 我错过了什么吗? 我认为托管代码中的这些异常应该是不可能的。 我在.net 4.7和4.5以及多台不同的计算机上都看到了它? 这是.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;
            }
        }
    }
}

此片段“通常”在一分钟内失败。

更新:它可能应该以64位运行。 如果使用“任何CPU”编译,则问题需要更长时间才能重现。

UPDATE2:使用我有:

usings

最初的Github问题( https://github.com/dotnet/corefx/issues/33157 )已作为https://github.com/dotnet/coreclr/issues/20690的副本关闭。 显然,这是一个已在.NET 4.8修复的已知问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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