Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Infinite Loop when pressing ESC

Author
Message
scotts7777
14
Years of Service
User Offline
Joined: 14th Mar 2010
Location: Victoria, BC
Posted: 6th Apr 2010 23:07
I'm writing a switch statement that gives four choices : 1,2 and 3 call functions and 6 exits the program. It all works great, but when I press ESC, it goes into an infinite loop of the "Default:" part of the switch statement.

Here's my code :


Any idea what could cause this behaviour? I've tried adding a counter to the while loop and changing it so that if the counter exceeds 10 loops it will exit the while loop, but this doesn't change a thing. It still goes into infinite loop when I press ESC.

Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 6th Apr 2010 23:28 Edited at: 6th Apr 2010 23:30
I think dbInput reads escape key presses into the buffer, so that's why it's going through default.

Put dbClearEntryBuffer() at the end of the loop.

And dbInput, the way that you are using it, is causing a memory leak every call. Use it this way:



Do you expect your program to exit when you press ESC? Because LoopGDK needs to be included in the while loop, because that's what checks for it.

As an alternative to dbInput, you could use dbInKey, which returns a char of the key being pressed.

"A computer once beat me at chess, but it was no match for me at kick boxing."
Emo Philips
scotts7777
14
Years of Service
User Offline
Joined: 14th Mar 2010
Location: Victoria, BC
Posted: 7th Apr 2010 06:38
Thanks for the help. Can you explain how my use of dbInput() is causing a memory leak? The code I'm using is exactly the same as the examples in the Gaddis book (Getting Started with C++).

I did notice that when I go to shut down the non responding program using Task Manager that the memory usage goes through the roof. I assume this is what you mean by memory leak.

As for what I'm expecting when ESC gets pressed, all I'm trying to do is read in user input so I can complete some of the chapter programming exercises. I got my programs to work, but I just found it very odd that pressing ESC caused the program to do the infinite loop, when I would have thought nothing would happen. I went back and tried other example code from the book and anytime ESC is pressed in a while loop, the same thing happens.

I'll keep working through this book and hopefully learn a bit more and be able to answer these questions myself, but if you could educate me on this memory leak business.


Login to post a reply

Server time is: 2024-10-02 03:40:34
Your offset time is: 2024-10-02 03:40:34