Type initializer exception OpenTK and monogame

走远了吗. 提交于 2021-02-10 22:28:20

问题


I just installed MonoGame and OpenTK 1.0 and in Visual Studio 2012 I made a new project of type 'Windows OpenGL Game`...but when I run the project I get the following error:

The type initializer for 'OpenTK.Graphics.GraphicsMode' threw an exception.

The error is right on this line (the consturctor, on the base())

public Game1()
    : base() 
{
    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
}

My laptop has intel oboard graphics 3000 and I think it supports OpenGL...thats the only thing I can would point to. Any ideas?


回答1:


We can look at the source code and find where the exception went unhandled. The "type initializer" basically means the static constructor:

static GraphicsMode()
{
    lock (SyncRoot)
    {
        implementation = Platform.Factory.Default.CreateGraphicsMode();
    }
}

Unfortunately digging through CreateGraphicsMode doesn't reveal any single obvious source for an exception.

What you should do now is try to get a stack-trace for that exception, and find out where it originates from within CreateGraphicsMode. The debugger should give you this information when the exception goes unhandled.


With a small amount of digging, without seeing a stack trace (so I'm pretty much guessing), I came across this potential culprit:

throw new GraphicsModeException(
    "No GraphicsMode available. This should never happen, please report a bug at http://www.opentk.com");

Which, of course, is extremely unhelpful. Although, based on its location, it would seem to indicate that it cannot find a suitable graphics mode.

At this stage, I think it would be best to build MonoGame and OpenTK from source so that you can use the debugger to see exactly what they're doing.




回答2:


This issue was happening to my as well, and I do not believe it's MonoGame's source code issues.

A) You need to make sure openTK is insstalled, http://www.opentk.com/

B) Like craftworkgames said, your machine (laptop I'm assuming) doesn't support OpenGL. I had this issue on my Sufrace Pro, and had to update my Intel drivers to the latest (I used guru3d.com and www.guru3d.com/files_categories/videocards_intel_graphics_drivers.html at this time installed the 15.31 drivers) and then it started working.



来源:https://stackoverflow.com/questions/17766944/type-initializer-exception-opentk-and-monogame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!