I've been trying to figure out what is happening when I run functions from the update loop in XNA that the game freezes for a few seconds until the function is done. When I do performance testing to see how long the function is taking its lower than what is actually being taken to do the function when timed by a stop watch on my phone.

Is there something that is going on with how XNA times its updates and draws that is causing this?

I'm using XNA since MonoGame works with it.

I've got IsFixedTimeStep = false in the constructor of my game that I'm building.

For the update code:

    protected override void Update(GameTime gameTime)
        // Allows the game to exit
        if (Keyboard.GetState().IsKeyDown(Keys.Escape))

        if (Keyboard.GetState().IsKeyDown(Keys.Space))
            doOnce = false;

        // TODO: Add your update logic here

        // trying to determine issue with game freezing when doing the function below.
        if (!doOnce)
            doOnce = true;
            startTime = DateTime.Now;
            endTime = DateTime.Now;

            timeTakenToScale = new TimeSpan(endTime.Ticks - startTime.Ticks);

        if (gameTime.TotalGameTime.TotalMilliseconds < nextFrameTime)    // don't draw the game unless its past its frame time
            nextFrameTime = gameTime.TotalGameTime.TotalMilliseconds + maxFrameRate;    // set next frame to time
  • \$\begingroup\$ You've probably got fixed timing on. See msdn.microsoft.com/en-us/library/bb203878.aspx \$\endgroup\$ – jzx Feb 2 '15 at 18:32
  • \$\begingroup\$ It's far more likely this is an issue with how you're timing things. Either way, we'd need significantly more information about how you're timing things, what kind of debugging you're done already and what the code looks like. \$\endgroup\$ – MichaelHouse Feb 2 '15 at 18:33

Ok I found out the issue. Apparently when I was doing the time calculation I forgot to put totalmilliseconds and had milliseconds. Feel like an idiot for sure. :(

| improve this answer | |

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.