Why does this game loop stop my process from responding?

Posted by Ben on Game Development See other posts from Game Development or by Ben
Published on 2013-05-02T21:25:41Z Indexed on 2013/07/02 5:15 UTC
Read the original article Hit count: 325

Filed under:
|

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?

© Game Development or respective owner

Related posts about c#

Related posts about game-loop