Why does this game loop stop my process from responding?
- by Ben
I implemented a fixed time step loop for my C# game. All it does at the moment is make a square bounce around the screen. The problem I'm having is that when I execute the program, I can't close it from the window's close button and the cursor is stuck on the "busy" icon. I have to go into Visual Studio and stop the program manually.
Here's the loop at the moment:
public void run()
{
int updates = 0;
int frames = 0;
double msPerTick = 1000.0 / 60.0;
double threshhold = 0;
long lastTime = getCurrentTime();
long lastTimer = getCurrentTime();
while (true)
{
long currTime = getCurrentTime();
threshhold += (currTime - lastTime) / msPerTick;
lastTime = currTime;
while (threshhold >= 1)
{
update();
updates++;
threshhold -= 1;
}
this.Refresh();
frames++;
if ((getCurrentTime() - lastTimer) >= 1000)
{
this.Text = updates + " updates and " + frames + " frames per second";
updates = 0;
frames = 0;
lastTimer += 1000;
}
}
}
Why is this happening?