views:

27

answers:

1

So it's well known that you're supposed to call game's base.Initialize() before using the game object's GraphicsDevice right? That's what I gathered from reading a lot of tutorials online.

Apparently that's not where game's GraphicDevice is created because I'm able to use it before base.Initalize() like this...

protected override void Initialize()
{
    // TODO: Add your initialization logic here

    // I use the game's GraphicsDevice in here to create a 
    // SpriteBatch, BasicEffect, ect. and it's VALID
    Engine.Initialize();

    base.Initialize();
}

What magic is happening in Game.Run() that would initialize the GraphicDevice?

A: 

The XNA documentation specifies that Initialize is "Called after the Game and GraphicsDevice are created, but before LoadContent." The tutorials that state otherwise are incorrect.

Game.Run creates a graphics device and then calls Initialize.

this.graphicsDeviceManager = this.Services.GetService(typeof(IGraphicsDeviceManager)) as IGraphicsDeviceManager;
if (this.graphicsDeviceManager != null)
{
    this.graphicsDeviceManager.CreateDevice();
}
this.Initialize();

You can use Reflector to investigate the internal code of the XNA assemblies yourself.

Empyrean