简体   繁体   中英

OpenTK: System.ExecutionEngineException at GLFW.PollEvents()

I am trying to create a 2D game using C# and OpenTK. For the engine part, I am roughly following this tutorial . Everything worked as it should until I tried to add texture batching. At that point I got the first ExecutionEngineException (EEE). Now even if I use the code from before the changes, I get an EEE. It is only resolved if:

  • I only use one RenderBatch
  • I don't pass the view and projection matrices and additional vertex attributes to the shader

As soon as I either pass the matrices or additional vertex attributes to the shader, an EEE is thrown.

I also got a System.AccessViolationException sometimes, but can't find a controlled environment to consistently recreate it.

The source code can be found here . The main problem file is RenderBatch.cs and the error occurs in Window.cs at line 95. The program is currently in a state in which it doesn't crash.

The amount of RenderBatches can be controlled in Renderer.cs at line six with the maxBatchSize constant and in GameScene.cs at the lines 21 and 22 (the amount of iterations). A new RenderBatch is created when all existing ones are full. Currently 10000 GameObjects are created. The maxBatchSize controls how many GameObjects fit into one RenderBatch.

Passing the view and projection matrix to the shader is achieved by uncommenting lines 87 and 88 in 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 .

For the environment I am using:

  • Visual Studio Community 2019 16.7.5
  • C# 8.0 with .NET Core 3.1
  • OpenTK 4.0.0
  • System.Drawing.Common 4.7.0
  • .NET SDK 5.0.100-rc.1.20452.10 but never uninstalled the latest stable version
  • Windows 10 Pro

I now solved the issue.

After I set the error callback for GLFW after GLFW.Init instead of before, I got an error log from GLFW. This error log corresponded to the one found here . Creating private fields for every callback even if it was a static method solved the issue for me.

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