Weird Problem with console buffer, but only after 30 iterations of some loop.

Ok you see I have this problem. I have been using GetConsoleScreenBufferInfo() and SetConsoleCursorPosition() repeatedly cout random numbers to the same spot on the same line, (thereby erasing the old numbers, so that the numbers appear to be constantly changing, which they are...) to simulate a 'ping pong' lottery number generator. The user may select a number at random by clicking the mouse. When the mouse is clicked, the last number couted to the screen is selected. How ever after about 30 iterations of user selecting 5 numbers each time, the GetConsoleScreenBufferInfo and SetConsoleCursorPosition functions or something go haywire, and instead of couting the numbers to the same spot on the line, it starts to add spaces after each number, and quickly fills the console buffer with garbage numbers and makes the program unusuable.

I have known about this bug for like 2 years but have always thought it was minor because simply restarting the program solves it.

But now I would like to fix it.

I thought about it and thought about it but I simply don't know enough about what is going on to be able to troubleshoot. (Is it some variable going out of scope? Is it some int being incremented to some point beyond its capacity? None of it sounds plausable to me, but then again what do I know. It cant be due to pointers because I'm not using any.

Appreciate the help.

I am at work now so I can't post the code, but I will try to do so tomorow. In the mean time can any of you think what might be causeing this?

What could be going on after the 30th iteration?

edit:
I forgot to mention that while debugging today I found some other abnormalities, that are probably not up to standard coding standards. Such as recursively calling functions to repeat etc.... could this be causing it?

P.S. although the vomit in question was occuring inside a for loop.... (however maybe its possible that something on the stack yada yada yada & will someone write me a program that asks questions for me so that I will sound like I know what I'm talking about? & maybe during the for loop the stack exploded.
Last edited on
Topic archived. No new replies allowed.