创建游戏类实例(OpenTKGameWindow.Initialize)时发生NullReferenceException [英] NullReferenceException when creating instance of Game class (OpenTKGameWindow.Initialize)

查看:173
本文介绍了创建游戏类实例(OpenTKGameWindow.Initialize)时发生NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在OSX上安装了xamarin和monogame,我试图运行一个在Windows上可以完美运行的非常基本的演示项目.但是我收到以下错误:

I just installed xamarin and monogame on OSX I have tried to run a really basic demo project that works perfectly on windows. But I get the following error:

System.NullReferenceException: Object reference not set to an instance of an object
  at Microsoft.Xna.Framework.OpenTKGameWindow.Initialize () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.OpenTKGameWindow..ctor () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.OpenTKGamePlatform..ctor (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.GamePlatform.Create (Microsoft.Xna.Framework.Game game) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.Game..ctor () [0x00000] in <filename unknown>:0
  at test.Game1..ctor () [0x00057] in /Users/remojansen/Desktop/test/test/Game1.cs:37
  at test.Program.Main () [0x00001] in /Users/remojansen/Desktop/test/test/Program.cs:19

代码没有错,因此我必须缺少DLL或其他东西吗?您对可能缺少的东西有什么想法吗?

There is nothing wrong about the code so I must be missing a DLL or something? Do you have any ideas about what could be missing?

谢谢:)

反汇编在第二行显示错误:

The disassembly shows a error in the second line:

00000155   callvirt IWindowInfo OpenTK.NativeWindow:get_WindowInfo ()
0000015a   ldnull 
0000015b   callvirt Object System.Reflection.PropertyInfo:GetValue (Object, Object[])
00000160   unbox.any System.IntPtr
00000165   stfld 
0000016a   call GraphicsMode OpenTK.Graphics.GraphicsMode:get_Default ()
0000016f   ldarg.0 
00000170   ldfld 
00000175   callvirt IWindowInfo OpenTK.NativeWindow:get_WindowInfo ()
0000017a   newobj Void OpenTK.Graphics.GraphicsContext:.ctor (GraphicsMode, IWindowInfo)

我还手动编译了OpenTK,当我运行示例时,它们似乎运行良好:

I have also manually compiled OpenTK and when I run the examples they seem to work fine:

我想问题出在单人游戏中,我使用xamarin单人游戏项目模板安装了单人游戏.

I guess the problem is in monogame, I installed monogame using the xamarin monogame project template.

推荐答案

Xamarin选择了错误的Monogame.Framework.dll.它正在尝试加载WindowsGL或Linux项目(使用OpenTKGamePlatform -对于MacOS,您希望在该堆栈跟踪中使用MacGamePlatform).

Xamarin picked up the wrong Monogame.Framework.dll. It's trying to load the WindowsGL or Linux project (which uses OpenTKGamePlatform -- for MacOS you want MacGamePlatform in that stack trace).

MonoGame Xamarin模板存在很多问题.其中之一是,它将始终选择错误的框架.您需要在/Users//Library/Application Support/XamarinStudio-4.0/LocalInstall/Addins/MonoDevelop.MonoGame.3.0.1/assemblies/MacOS

The MonoGame Xamarin template has a lot of problems. One of them is it will always pick the wrong framework. You need to manually browse to the framework dll in /Users//Library/Application Support/XamarinStudio-4.0/LocalInstall/Addins/MonoDevelop.MonoGame.3.0.1/assemblies/MacOS

但是,如果您使用的是3.0.1版本,则仍然存在问题-存在MonoMac.dll API冲突.我强烈建议下载最新的MonoGame源代码,并自己构建MonoGame.Framework.MacOS项目,并在此引用框架程序集.您仍然可以使用已安装的Xamarin模板,只需更改程序集引用即可.您可能还需要将logo.png构建操作设置为内容"才能完全开始.

However, there's still problems with that if you're using the 3.0.1 release -- there's a MonoMac.dll API conflict. I strongly recommend downloading the latest MonoGame source code, and building the MonoGame.Framework.MacOS project yourself, and referencing the framework assembly there. You can still use the Xamarin template you installed, just change the assembly reference. You might also need to set your logo.png build action to 'Content' to fully get going.

这篇关于创建游戏类实例(OpenTKGameWindow.Initialize)时发生NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆