1
\$\begingroup\$

i have some issues why my GameEditor. I would start my XNA project from it, like a debug-client. It opens and all works fine, but it runs on 45 frames until I hide the wpf form. then the framerate goes up and remains there, even if I return the wpf form.

    private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
    {
        var gameAppDomain = AppDomain.CreateDomain("Game");
        gameAppDomain.ExecuteAssembly(@"..\..\..\WindowsGame1\WindowsGame1\bin\x86\Debug\WindowsGame1.exe");
    }

the game is a just a new xna game without any rendering, except my framerate counter.

/// <summary>
///     This is the main type for your game
/// </summary>
public class Game1 : Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    private FrameRateCounter frameRateCounter;

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

    /// <summary>
    ///     Allows the game to perform any initialization it needs to before starting to run.
    ///     This is where it can query for any required services and load any non-graphic
    ///     related content.  Calling base.Initialize will enumerate through any components
    ///     and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here
        this.frameRateCounter = new FrameRateCounter(this);
        base.Initialize();
    }

    /// <summary>
    ///     LoadContent will be called once per game and is the place to load
    ///     all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        this.spriteBatch = new SpriteBatch(this.GraphicsDevice);
        this.frameRateCounter.LoadContent();
        // TODO: use this.Content to load your game content here
    }

    /// <summary>
    ///     UnloadContent will be called once per game and is the place to unload
    ///     all content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    ///     Allows the game to run logic such as updating the world,
    ///     checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        this.frameRateCounter.StartUpdateTimer();

        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here

        base.Update(gameTime);
        this.frameRateCounter.EndUpdateTimer(gameTime);
    }

    /// <summary>
    ///     This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        this.frameRateCounter.StartDrawTimer();
        this.GraphicsDevice.Clear(Color.CornflowerBlue);

        // TODO: Add your drawing code here

        this.frameRateCounter.EndDrawTimer(gameTime);
        base.Draw(gameTime);
    }
}

If I do the same for a WinForms application, I dont have that issue. My first try was to launch it in an TASK/Thread but then it crashes after 15-20 min if I have loaded my soundeffects. The event log says it was "XAudio2_6.dll_unloaded" with a access violation exception.

hre is my test game: https://www.dropbox.com/s/gtt49lwquyoo86e/WindowsGame1.zip?dl=0

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Admittedly, this is an educated guess, so keep that in mind;

WPF being the parent domain in this case means that all subprocesses like the XNA game are issued handles from that domain. I don't really know enough about the architecture behind WPF to adequately explain what it would be doing to cause the slowdown. However, as a possible fix, try automatically minimizing and then restoring the game at launch?

\$\endgroup\$
1
  • \$\begingroup\$ yes, but I won't :) if you do it many times, your eyes hurt. I look for a real solution. \$\endgroup\$
    – EnemyArea
    Jan 20, 2016 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .