Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bioagentX

Infinite loops in windows XP

This topic is 5634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have windows XP, and for some reason, whenever I execute a program with an infinite loop, my computer crashes. Well, it''s not that it crashes, it''s that I can''t end the program. I can''t press the little x in the top right corner of the window, and I can''t even end the task from the tesk menu. Does anyone have a solution to my problem?

Share this post


Link to post
Share on other sites
Advertisement
Windows works with messages. When you click the X at the top right of the window, you are sending the application that created the window a message, saying you want the window to close. The messages get stored in a queue, ready for the application to collect them.

If your application is in an infinite loop, it has to check the message queue every so often if it''s going to take any action based on the messages.

Harry.

Share this post


Link to post
Share on other sites
don''t use an infinite loop

the infinite loop "blocks" the windows message processing so the window won''t respond.

Do it like this:


  
bool imrunning = true;
while (imrunning)
{
while (peekmessage(blah))
{
if (blablabla) imrunning = false;
TranslateMessage(foo);
Dispatchmessage(foo);
}
// process here

}

// this is pseudo code of course



If, with infinite loop, you are not referring to your game loop you might want to use threads... (google / mdsn)

Share this post


Link to post
Share on other sites
In windows programming, actions are based on messages. If your program goes into an infinite loop, it wont receive/generate messages(such as "close window" message that is generated by clicking the upper right cross on the window ). And therefore cannot process it!

If you need an infinite loop, you probably need multithreading.

Oztan.

Share this post


Link to post
Share on other sites
build in a mechanism by which your program can end the loop and exit gracefully. writing a program that can only be ended by killing the window is bad form b/c it means you''ll soon end up with memory leaks.

just do something like:


  
bool endLoop = false;

void killProgram() {
endLoop = true;
}

void doMemoryCleanup() {
//do any memory cleanup on global vars here

}

int mainLoop() {
while(1) {
if (endLoop)
break;

//do loop stuff

}

doMemoryCleanup();
}


in your WinProc method make the pressing of the ESC key call the killProgram() method. or instead of checking if (endLoop) do something like if (isKeyDown(''VK_ESC'')) break;

for info on WinProc, key detection stuff and a different way to exit infinite loops, check out the nehe tutorials on this site which implement said items

-me

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!