简体   繁体   English

为什么此代码抛出System.ExecutionEngineException

[英]Why this code throws System.ExecutionEngineException

Background: I am using DirectX 9.0 Managed Libraries to transform arrays of 3d points to 2d screen coordinates. 背景:我使用DirectX 9.0托管库将3d点数组转换为2d屏幕坐标。 For speed I use the UnsafeNativeMethods to do all the transformations. 为了速度,我使用UnsafeNativeMethods来完成所有的转换。

The Problem: If my custom line clipping function is used my application dies without throwing any exceptions, it took me a while to figure out that it was throwing an uncatchable System.ExecutionEngineException . 问题:如果使用我的自定义行剪切功能,我的应用程序死了而不会抛出任何异常,我花了一段时间才发现它抛出了一个无法捕获的 System.ExecutionEngineException I have narrowed it down to happening because of the last two lines of my clipping function. 由于剪切功能的最后两行,我已经缩小了它的范围。

List<Vector3> verticesAfterClipping = new List<Vector3>;
public unsafe void ClipLine(Line lineToClip)
{
    this.verticesAfterClipping.Clear();

    // Clipping algorithm happens here... (this is psuedo-code of what it does)
    foreach(Vertex in lineToClip.Vertices)
    {
        bool thisIsClipped =   // Set to whether this vertex is clipped
        bool lastWasClipped =  // Set to whether last vertex was clipped

        if(thisIsClipped == false && lastWasClipped == true)
        {
            verticesAfterClipping.Add( /* intersection on clipping plane */ );
            verticesAfterClipping.Add( /* thisVertex */ );
        }
        else if (thisIsClipped == false && lastWasClipped == false)
        {
            verticesAfterClipping.Add( /* thisVertex */ );
        }
        else if (thisIsClipped == true && lastWasClipped == false)
        {
            verticesAfterClipping.Add(/* intersection on clipping plane */);
        }
    }

    // THIS IS WHERE BAD THINGS HAPPEN
    lineToClip.Vertices = new Vertex[verticesAfterClipping.Count];
    verticesAfterClipping.CopyTo(lineToClip.Vertices, 0);
}

When the verticesAfterClipping list is copied to the lineToClip vertices the lineToClip object is then passed to an UnsafeNativeMethod which transforms these vertices to 2d vertices. verticesAfterClipping列表复制到lineToClip顶点时, lineToClip对象将传递给UnsafeNativeMethod,后者将这些顶点转换为2d顶点。 From everything I can see when I step through it in Debug mode it is working completely fine, until it just dies. 从我在调试模式中逐步完成它时可以看到的一切,它完全正常,直到它完全消失。

I simply cannot figure out what is wrong. 我根本无法弄清楚出了什么问题。 Any help would be much appreciated. 任何帮助将非常感激。

The problem may not actually be occurring in the line that throws an exception. 实际上可能不会在抛出异常的行中发生此问题。 This may just be a symptom of something that happened earlier. 这可能只是之前发生的事情的症状。

The System.ExecutionEngineException exception is thrown when the CLR detects that something has gone horribly wrong. 当CLR 检测到某些内容出现严重错误时,抛出System.ExecutionEngineException异常。 This can happen some considerable time after the problem occurred. 这可能在问题发生后相当长的一段时间内发生。 This is because the exception is usually a result of corruption of internal data structures - the CLR discovers that something has got into a state that makes no sense. 这是因为异常通常是内部数据结构损坏的结果--CLR发现某些东西已进入一种无意义的状态。 It throws an uncatchable exception because it's not safe to proceed. 它抛出一个无法捕获的异常,因为它不安全。

So you might have some code in some completely unrelated part of the system that corrupts something, but this only becomes apparent when this particular piece of code runs. 因此,您可能在系统中某些完全不相关的部分中有一些代码会破坏某些内容,但这只有在这段特定代码运行时才会变得明显。 The code you've shown might be just fine. 您展示的代码可能很好。 (It also might not be...I don't see anything obvious wrong, but then I don't know the DX 9 managed libraries well. I can't see which feature of this method requires the unsafe keyword, for example.) (它也可能不是......我没有看到任何明显的错误,但后来我不知道DX 9托管库。例如,我无法看到此方法的哪个功能需要unsafe关键字。 )

Unfortunately, this means you need to start casting the net a bit wider. 不幸的是,这意味着你需要开始更宽一点的网络。 Pretty much anything that uses either unsafe code, or COM interop is potentially suspect. 几乎任何使用不安全代码或COM互操作的东西都可能是可疑的。 This will be a long and tedious process, sadly. 遗憾的是,这将是一个漫长而乏味的过程。 One way you might approach it is to try gradually simplifying the program: what's the smallest piece of code that can illustrate the problem? 您可能采用的一种方法是尝试逐步简化程序:可以说明问题的最小代码是什么? (Eg, if you put the code you've shown there into an application that contains nothing else except the simplest possible call to that method, does it still fail?) (例如,如果你把你在那里显示的代码放到一个除了对该方法最简单的调用之外什么都没有的应用程序中,它仍然会失败吗?)

I have the same problem with different libraries. 我对不同的库有同样的问题。 In my case all started long before because I had to run a 32 bit .net app in a 64 bit environment. 在我的情况下,所有开始很久以前因为我必须在64位环境中运行32位.net应用程序。 Well this cause me a lot of trouble, the compatibility between architectures, or between the CLR of your .NET framework may be your problem too. 这给我带来了很多麻烦,架构之间的兼容性,或.NET框架的CLR之间的兼容性也可能是你的问题。

PS: Now I know what my trouble is but have no idea where is it. PS:现在我知道我的麻烦是什么,但不知道它在哪里

I have two classes that deal with a particular table in my database 我有两个类来处理我的数据库中的特定表

StorageManager - a class that has methods that handle the direct interactions with the database StorageManager - 具有处理与数据库的直接交互的方法的类

Controller - a class that has methods to handle the api calls Controller - 一个具有处理api调用的方法的类

When a new entry in the table is about to be created, I check child tables for certain values that might already exist. 当即将创建表中的新条目时,我会检查子表中是否存在可能已存在的某些值。

I wrote these methods to check for pre-existing/duplicates in the wrong class, which ended up causing the executingengineexception to get thrown for me. 我编写了这些方法来检查错误类中的预先存在/重复,最终导致执行initngneineexception被抛出。

Moving the methods so that they lived with the correct database context seemed to fix it for me. 移动方法使它们与正确的数据库上下文一起生活似乎为我解决了这个问题。

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

相关问题 读取 Azure 密钥保管库会引发异常:System.ExecutionEngineException:“引发了‘System.ExecutionEngineException’类型的异常。” - Reading Azure key vault throws exception: System.ExecutionEngineException: 'Exception of type 'System.ExecutionEngineException' was thrown.' 给定System.ExecutionEngineException的GetMessage() - GetMessage() given an System.ExecutionEngineException 抛出System.ExecutionEngineException - System.ExecutionEngineException being thrown DBContext 构造函数中的 System.ExecutionEngineException - System.ExecutionEngineException in DBContext Constructor Windows服务的System.ExecutionEngineException - System.ExecutionEngineException With Windows Service Windows 10设备上的System.ExecutionEngineException - System.ExecutionEngineException on Windows 10 device 仅在调试时才发生System.ExecutionEngineException - System.ExecutionEngineException only when debugging 如何找到 System.ExecutionEngineException 异常的来源 - How to find source of System.ExecutionEngineException Exception 附加到 Revit 过程失败并出现 System.ExecutionEngineException - Attach to Revit process fails with System.ExecutionEngineException OpenTK:GLFW.PollEvents() 处的 System.ExecutionEngineException - OpenTK: System.ExecutionEngineException at GLFW.PollEvents()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM