OpenTK:System.ExecutionEngineException 和 GLFW.PollEvents()

OpenTK: System.ExecutionEngineException at GLFW.PollEvents()

我正在尝试使用 C# 和 OpenTK 创建 2D 游戏。对于引擎部分,我大致遵循this tutorial。一切正常,直到我尝试添加纹理批处理。那时我得到了第一个 ExecutionEngineException (EEE)。现在即使我使用更改之前的代码,我也会得到一个 EEE。只有在以下情况下才会解决:

只要我将矩阵或附加顶点属性传递给着色器,就会抛出 EEE。

有时我也有 System.AccessViolationException,但找不到可控环境来始终如一地重新创建它。

可以在第 95 行 here. The main problem file is RenderBatch.cs and the error occurs in Window.cs 找到源代码。 程序目前处于不会崩溃的状态。

RenderBatches 的数量可以在Renderer.cs at line six with the maxBatchSize constant and in GameScene.cs 的第21 和22 行(迭代量)中进行控制。当所有现有的 RenderBatch 都已满时,将创建一个新的 RenderBatch。目前创建了 10000 个游戏对象。 maxBatchSize 控制一个 RenderBatch 可以容纳多少个游戏对象。

将视图和投影矩阵传递给着色器是通过在 RenderBatch.cs and passing more vertex attributes to the shader is achieved by integrating the commented in line 21 and uncommenting lines 72 to 75 and 158 to 161 also in RenderBatch.cs.

中取消注释第 87 和 88 行来实现的

对于我使用的环境:

我现在解决了这个问题。

我在 GLFW.Init 之后而不是之前为 GLFW 设置了错误回调之后,我从 GLFW 得到了一个错误日志。此错误日志对应于找到的 here。为每个回调创建私有字段,即使它是静态方法也为我解决了这个问题。