Name: Anonymous 2009-07-10 23:19
I wrote a quickie program that does a 2D random walk. It works fine for a while, but after around 250,000 loops, it stops drawing. WAT'S WRONG /PROG/?? D:
void DoStuff(HWND hwnd, HDC hdc) {
WINDOWINFO wnd;
int xmax, ymax, x, y, r;
srand((unsigned int)time(0));
GetWindowInfo(hwnd, &wnd);
xmax = wnd.rcClient.right - wnd.rcClient.left - 1;
ymax = wnd.rcClient.bottom - wnd.rcClient.top - 1;
x = xmax / 2; y = ymax / 2;
while (1) {
SetPixel(hdc,x,y,0);
if ((r = (rand() % 4)) >= 2)
x = (x + (2*(r % 2)-1) + xmax) % xmax;
else
y = (y + (2*(r % 2)-1) + ymax) % ymax;
}
}