# XNA application stops updating the screen

This topic is 2638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,
This seems to happen at random; my Game class is not fundamentally different to the platformer sample; im using XNA 4.0 on win7.

		protected override void Update(GameTime gameTime)		{			float delta = (float)gameTime.ElapsedRealTime.Milliseconds / 1000f;			grid.update(delta);			mouseInputHandler.update(delta, this);				base.Update(gameTime);		}		protected override void Draw(GameTime gameTime)		{			renderer.startFrame();				grid.Draw(renderer);				renderer.drawText("GUIFont", "Iteration:" + grid.Iteration, new Vector2(1000, 20), Color.Yellow);			renderer.endFrame();			base.Draw(gameTime);		}

What happens is that, seemingly at random, the game will stop repainting the screen. I can trick it into repainting by doing things like dragging the window around, alt+tabbing out etc.

I have no idea where to look and my searches have not been forthcoming. Does anybody know what can cause this? im setting the resolution of the framebuffer with graphics.PreferredBackBufferHeight and Width, but I doubt this is going to cause such a problem. The platformer sample works just fine, and there is no code related to framebuffers in any of the things I am calling from update or draw. it was happening just the same before I moved my spriteBatch into my renderer class.

##### Share on other sites
It seems I have fundamentally misunderstood something; am I right in thinking that Update only gets called when there is some kind of change in state? When I added a frame counter and incremented it in the Draw function, I found that even when my application had "stopped" the frame counter was still running.

Is this normal behaviour?

##### Share on other sites
Update will be called every 1/60th of a second if IsFixedTimeStep is true, or as fast as possible if not.

Are you sure your update is not being called, or is it just that your custom code is not running correctly?

Have you tried running this on another computer?

Edit: Are you possibly doing something in one of your other classes that causes a blocking update of the process, like waiting on network activity? or possibly something that takes a long time?

Edit2:
Oh and not that it should make much difference, but why don't you use

(float) gameTime.ElapsedGameTime.TotalSeconds

instead of dividing Milliseconds by 1000 to get the same value, costing you an extra division in the process for no gain?

Edit3:
In writing the above, I noticed you are using ElapsedRealTime.. This means you aren't using XNA 4. Don't use Real time, use Game time. Microsoft removed Real time for a reason (and is quite probably the reason for your issues).

Edit4: I just felt I hadn't edited this post enough.

##### Share on other sites
Ahh, ElapsedGameTime fixed it. I don't know why ElapsedRealTime is still in there if it doesn't work. Surely the only acceptable behaviour is for it to denote the amount of elapsed real time since it was last accessed? The page on MSDN doesnt mention any unusual behaviour.

Also, casting the number of seconds to a float isn't going to give me fractions of a second, which is what I need. Passing around the delta time as fractions of a second is actually more optimal because I can perform a single multiplication to make things framerate independent, for example multiplying a motion vector by a scalar time delta.