0
\$\begingroup\$

I've been experiencing a really Strange problem since recently, Every variables of XNA Framework Game class seems not to be initialized before my extending Game1 class. Variables does not seem to be initialized before the point where they should be.

I do not plan to change the game engine, but I'll appreciate any help of any kind.

Thanks for your time

here is my Game1 class (a small part of it)

public class Game1 : Game
{
  public static GraphicsDeviceManager graphics;
  public static SpriteBatch spriteBatch;
  public static ContentManager ContentManager;
  public static SceneManager SceneManager { get; private set; }
        
  public Game1()
  {
    ContentManager = Content;

    graphics = new GraphicsDeviceManager(this);
    ContentManager.RootDirectory = "Content";


    // TODO: Add your initialization logic here
    /*
    GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height
    GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width
    */
    Window.IsBorderless = true;
    graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
    graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
    IsMouseVisible = true;

  }

    (...) //The code continues
}

and here is the errors:

enter image description here

enter image description here

enter image description here

the Null pointer error on the Window variable occures when i declare a new Content manager


Edit:

It seem that there is a conflict between System.RunTime.Serialization v4 and v2 in my project

1>  Impossible de résoudre le conflit entre "System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" et "System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes". Choix arbitraire de "System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
\$\endgroup\$
  • \$\begingroup\$ Found this, come back after reading github.com/MonoGame/MonoGame/issues/5787. also this stackover question did not helped: stackoverflow.com/questions/16999469/… \$\endgroup\$ – Louis BERTRAND Jun 21 '20 at 16:16
  • \$\begingroup\$ tried to delete bin folders - did not worked, tried to build on vs17 - did not worked, i cannot try to open the solution on vcs2010 express because the project has been created on a newer version. I'll try to create a new project reimport one by one the nuget packages and copy my code \$\endgroup\$ – Louis BERTRAND Jun 21 '20 at 17:46
  • \$\begingroup\$ still having the problem after creating an other project and copied the code and content \$\endgroup\$ – Louis BERTRAND Jun 21 '20 at 20:00
  • \$\begingroup\$ Okay apparently it worked, I had an error because I moved my sprite batch declaration in the constructor but it's not supposed to be there. But yeah I'll create an answer with the method to overcome this problem \$\endgroup\$ – Louis BERTRAND Jun 21 '20 at 20:06
0
\$\begingroup\$

Problem solved

i solved it by creating a new Monogame project and copying the code and the content folder into my new project folder. I did not copied the 'bin/', 'obj/', 'packages/', 'x86/' & 'x64/', 'Content/bin' and 'Content/obj' since they are built automatically. then I rebuilt the content pipeline. Everything works fine except a spriteFont not loading because I've voluntarily deleted it at some point. Note that if you do like me you will need to reimport libraries that you used and worked before having your problem.

conclusion I can get from my experience, Bad usage of some libraries can cause the project to break for ever. In my case, the game class was not initializing.

Hope this will help everyone in my situation.

bye

\$\endgroup\$
  • \$\begingroup\$ also if somebody has a good tutorial in mind to import .ttf files with a sprite font I'll be really thankful \$\endgroup\$ – Louis BERTRAND Jun 21 '20 at 20:14
  • \$\begingroup\$ Regarding the ttf files, you can see if SpriteFont 2 is right for you - it can generate necessary files if you want it to. \$\endgroup\$ – htmlcoderexe Jun 21 '20 at 22:30
  • \$\begingroup\$ thanks I'll take a look \$\endgroup\$ – Louis BERTRAND Jun 21 '20 at 23:07
  • \$\begingroup\$ For the Font problem I came up with the use of the library called SpriteFontPlus.MonoGame which is just what I needed, no need to use content importer, only ttf file, Cleary simplifying the way to import fonts. github.com/rds1983/SpriteFontPlus & nuget.org/packages/SpriteFontPlus.MonoGame \$\endgroup\$ – Louis BERTRAND Jul 29 '20 at 22:25
  • \$\begingroup\$ Huh, nice to know. Keep font copyrights in mind, especially if you're going to be releasing something - sometimes there's like a 100x price difference between being able to use the .ttf itself vs one sheet of rendered font at a specific size. \$\endgroup\$ – htmlcoderexe Jul 30 '20 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.