PDA

View Full Version : OpenGL/GLUT glutTimerFunc bug


Brad
2005-10-20, 05:24
Is anyone here familiar with a bug in Mac OS X's OpenGL implementation that causes a glutTimerFunc call to fire immediately instead of waiting for the specified time (in milliseconds)?

Apparently this was a known bug a long time ago (I found some documents in Google from early-mid 2002) but I was not able to find if it was ever fixed by Apple or if there's some kind of ugly hack I could implement to "fix" it to work like it should.

This is just driving me bonkers and is seriously screwing up a program I've been working on for a while. I can't implement any low-level timers (less than a second) because this code needs to be platform-independent and run on Windows as well.

Also, does anyone know if there are any newer builds of OpenGL being tested at connect.apple.com? The latest thing I see there was from December 2004. If you don't want to reveal anything publicly, please private message me.

Thanks in advance. :)

Brad
2005-10-25, 05:11
Nothing at all?

Am I really the only OpenGL programmer at AppleNova? :\

chewman
2005-10-25, 07:07
i'm an ex pat OpenGL programmer.. well ex programmer full stop; Programming made me cry... :o In any case, I'm sorry that I cant offer any assistance.

Brad
2005-10-25, 09:19
Okay, thanks anyhow. :)

I know for a fact, now, that this is a bug in Apple's OpenGL implementation. I tried my code on a Windows XP box (blech!) and it worked PERFECTLY. On my Macs? One of the timers randomly fires immediately instead of waiting.

*shrug*

I've figured out a dirty dirty workaround. I'm going to try using the clock method from timer.h to double-check that a given timer isn't firing too early. Unfortunately, clock() on Mac OS X only counts centiseconds whereas on Windows it counts milliseconds.

I guess I need to file a bug with Apple about this...

thuh Freak
2005-10-25, 12:10
well, since u know its a bug in apple's opengl, you could put in a macro around it, specific for apple, ie:

#ifdef APPLE
sleep( /*int seconds;*/ );
#endif
glutTimerFunc( func_ptr );

or, do something like this:
void my_timer_func()
{
#ifdef APPLE
static BOOL first_time = YES;
if (first_time) { first_time=NO; return; }
#endif
// rest of func
}

i'm pretty sure APPLE is an implicit definition from apple's gcc.

ezkcdude
2005-11-15, 18:10
Brad, since you appear to be the OpenGL guru, have you tried the OpenGL Shader Builder using GLSL? It's so buggy that it crashes even if I just type one line of code and then hit enter. I'm surprised Apple hasn't a) realized this yet or b) hasn't bothered to fix it. It seems like it would be a nice little environment to learn shader coding, which is something I want to do. If you haven't ever looked at this program, I'd urge you to try it out and report back here. Thanks.

Dave
2005-11-16, 14:38
well, since u know its a bug in apple's opengl, you could put in a macro around it, specific for apple, ie:

#ifdef APPLE
sleep( /*int seconds;*/ );
#endif
glutTimerFunc( func_ptr );

or, do something like this:
void my_timer_func()
{
#ifdef APPLE
static BOOL first_time = YES;
if (first_time) { first_time=NO; return; }
#endif
// rest of func
}

i'm pretty sure APPLE is an implicit definition from apple's gcc.
I second this notion. You could say "#ifdef ANNOYING_APPLE_GLUT_TIMING_BUG" or somesuch thing instead of "#ifdef APPLE" so that your work around has a more precise label. I can't think of any better idea though.

mtolson
2005-12-15, 17:14
I can confrim that the timer func ignores the msec. parameter that is passed in. I suppose that a workaround would be to use the idle callback - yuk. I plan to go to freeGlut. My first Apple disappointment.

Brad
2005-12-15, 19:07
Thank you for the confirmation, mtolson. I ended up doing development strictly on a Windows machine and giving up hope of having easy cross-platform code. Pretty sad. :\

And welcome to AppleNova! :)

nedelec
2006-01-06, 04:09
I confirm the bug in glutTimerFunc() on mac OS X.
I was trying to get a call back after 2 sec, but glutTimerFunc() would fire back immediately, sometimes. A workaround was to use 10 callbacks instead of a single one:

void startTimer()
{
glutTimerFunc(200, timer, 10); //this will call timer(10)
}

void timer(int cnt)
{
if ( cnt > 0 )
glutTimerFunc(200, timer, cnt-1);
else
performAction();
}

This worked for me: performAction() is called after ~2 sec.
The code remains the same on all platforms.
The accuracy of the timing might not be very good, I did not check it.

Best,
Fr.

azcoder
2006-01-08, 23:59
I have recently become a new iMac owner :-) ....and I am trying to port my win/linux OpenGL game to mac. I am using SDL for input/windowing.... The SDL timer functions seem to be working, so this might be another cross-platform option for you instead of glut.

Also, I am attempting to use XCode instead of emacs. Is XCode a decent environment in your opinion?




Good luck......

Brad
2006-01-09, 00:06
At the time, SDL was not an option because GLUT was required for use in a university class. Yes, Xcode (not "XCode") is a good environment in my opinion. I can't stand trying to work with large files of code in vi/emacs.

That's an interesting workaround that you found, nedelec. If I ever get motivated to dig through my old code, I'll have to try that.