Hi
try this:
KeyPressed()
{
static bool sbProcessingKey = false;
if (sbProcessingKey)
{
return;
}
sbProcessingKey = true;
////write here your keys handling code
sbProcessingKey = false;
}
If this doesn’t help, I suggest you to debug your program more, and to find really where it crashes…
Regards
Martin
[This message has been edited by martin_marinov (edited 04-16-2002).]
Martin’s code, roughly speaking, prevents the function from re-entering itself.
Anyways, I doubt it will help. You need to post a lot more info if you want help. Like, where EXACTLY is it crashing? (Hint: you need a debugger to know this). What is the code doing there? etc etc etc
void keyboard ( unsigned char key, int x, int y )
{
switch ( key ) {
case ‘z’:
scale += 10.0f;
break; // Ready For Next Case
default: // Now Wrap It Up
break;
}
}
I couldnt use my debugger on my program. Somehow it runs through my glut codes without going into the function.
However, my program have a tendency to crash whenever I pressed on ‘z’ too fast. I think the system registers double clicks instead and hence is unable to function normally.
Therefore, I am hoping that someone have caught this exception before and can help me.
Originally posted by muzz:
I couldnt use my debugger on my program.
Uhm… why not?
$ gdb <name of program>
(gdb) run
… press ‘z’ a bunch of times and note where it crashes. Type ‘bt’ for a stack trace. Type ‘list’ for a listing of code.
You know how to use gdb, right?
Somehow it runs through my glut codes without going into the function.
What does this mean, exactly? How do you know this? If it doesn’t go in to your function, how can your function be to blame?
However, my program have a tendency to crash whenever I pressed on ‘z’ too fast.
Again, you’ve given way too little info for anyone to give you any meaningful help.
I think the system registers double clicks instead and hence is unable to function normally.
Or it could be phase of the moon isn’t quite right… seriously, anything is possible with the very little info that you’ve presented.
Hi
muzz - try really to debug your program - my code may help (I doubt it will however), but it can hide something wrong somewhere in your code …
Learn to use a debuger - if not gdb, then the internal debuger of kdevelop. When you compile your program just use the -g switch of gcc and so on.
Hi
this code, as rts explained, prevents the function of reentering - this means that it will be not able to process another key event, while you are processing the current one. This can happen if you are using threads, or somehow you are generating another key input while processing the current one. The last should not happend if you don’t have more than one thread and your code is correct.
As I said in my previous post, I doubt that my code will help. So learn to use a debuger - this is the best advice which I can give you…