Sign in to follow this  
speciesUnknown

XNA application stops updating the screen

Recommended Posts

speciesUnknown    527
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 this post


Link to post
Share on other sites
speciesUnknown    527
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 this post


Link to post
Share on other sites
BLiTZWiNG    361
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 this post


Link to post
Share on other sites
speciesUnknown    527
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this