infinite loop causing program to crash

Dec 24, 2012 at 2:23am
I got win32 application, that runs a infinite for loop, which increment a value inside the loop. the problem am having is that my application become unresponsive and uses alot of CPU when compiled.

my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
case IDM_ROTATION:
			
			for(int i = 0; i < 4; i++)
			{

				i = 0;

				rotation += rotationIncrement;
				InvalidateRect(hWnd, NULL, TRUE);
				UpdateWindow(hWnd);
			}

			break;


How can i fix this?, I just want a loop or timer that increment my rotation variable every second.
Last edited on Dec 24, 2012 at 2:43am
Dec 24, 2012 at 5:22pm
Then use a Windows timer rather than a for loop. That is a quite poor way to go about it in my opinion (what you have shown).

If you use a timer, you can either have the message sent to your Window Procedure, or have it directed to a callback for which you've specified a name. Check out WM_TIMER and SetTimer().
Dec 24, 2012 at 6:28pm
Please delete line 6, this causes your infinite loop.
Dec 29, 2012 at 3:49am
Thanks @freddie1 and @modoran used the windows timer and it worked.
Dec 30, 2012 at 4:44am
every time the loop runs, "I's" value is set to zero so it will never be anything other than zero. Delete that.
Topic archived. No new replies allowed.