Search code examples
windows-phone-8xamarinxnamonogame

NuGet MonoGame WindowsPhone 8.0


I have a problem integrating MonoGame into an existing WindowsPhone8.0 project.
Everything seems to work fine, but when is start the app it's crashing with NullPointerException in MonoGame Framework.

StackTrace:

at MonoGame.Framework.WindowsPhone.WindowsPhoneGameWindow..ctor(Game game)
at MonoGame.Framework.WindowsPhone.WindowsPhoneGamePlatform..ctor(Game game)
at Microsoft.Xna.Framework.GamePlatform.PlatformCreate(Game game)
at Microsoft.Xna.Framework.Game..ctor()
at myApp.Game1..ctor()
at myApp.myPage..ctor()

EDIT: I have also tried that: link


Solution

  • Based on the stack trace your myPage constructor goes somewhat like this:

    _game = new Game1();
    

    The Windows Phone project template, however, does it this way:

    _game = XamlGame<Game1>.Create("", this);
    

    The latter version does lots of initialization, for example stores a reference to the XAML page for framework use. The first version crashes because the said initialization is not done, and tries to access null page.