Monday, September 24, 2018

xna - Why my game is running slowly if it was launched from a wpf application?


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.


/// 
/// This is the main type for your game
///

public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

private FrameRateCounter frameRateCounter;

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

///
/// 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.
///

protected override void Initialize()
{
// TODO: Add your initialization logic here
this.frameRateCounter = new FrameRateCounter(this);
base.Initialize();
}


///
/// LoadContent will be called once per game and is the place to load
/// all of your content.
///

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
}

///
/// UnloadContent will be called once per game and is the place to unload
/// all content.
///

protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here

}

///
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
///

/// Provides a snapshot of timing values.
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);
}


///
/// This is called when the game should draw itself.
///

/// Provides a snapshot of timing values.
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




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...