Desperate help needed with GLUT callbacks

Member
Posts: 22
Joined: 2006.04
Post: #1
My apologies - I'm aware this is a forum for MacOS, advice on where better to ask this question would be as appreciated as a solution to my problem.

My MSc project using GLUT needs to be demoed on Monday. It compiles and runs flawlessly with XCode (not even a warning). But they want me to demo it on a Windows box using Visual Studio .NET 2003 (yurgh). I've got it to build, but it throws an exception "Access Violation" when registering the display callback.

Code from my controller class header (IVOR.h):

Code:
    void setDisplayCallback();
    void setIdleCallback();
    static void display();
    static void idle();

From the .cpp file:

Code:
void IVOR::setDisplayCallback()
{
    glutDisplayFunc(&display); // breaks here apparently
}

void IVOR::setIdleCallback()
{
    glutIdleFunc(&idle);
}

void IVOR::display()
{
    IVORClient::getInstance()->draw();
}

void IVOR::idle()
{
    IVORClient::getInstance()->idle();
    glutPostRedisplay();
}

Everywhere I look on the net people say if you declare the callback functions as static then it works fine - only the display one seems to be broken.

Help?

Flash!
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #2
A couple of things to check:
Is display a member function of IVOR? Then you should probably pass IVOR::display instead of &display. Note that I removed the & sign.

Secondly, try running it through XCode with GuardMalloc turned on. Search the forum for GuardMalloc for more info. Smile
Quote this message in a reply
Member
Posts: 22
Joined: 2006.04
Post: #3
display() is a member function of IVOR. I tried IVOR::display (and &IVOR::display and display as well :s ) but I get exactly the same crash.
I enabled guard malloc and used 'debug executable' from the debug menu (that's right isn't it?) and, aside from running very slowly, everything seemed fine in XCode.

Flash!
Quote this message in a reply
Member
Posts: 87
Joined: 2006.08
Post: #4
Try removing the & glutDisplayFunc(). The value you are passing in is already a pointer, and glutDisplayFunc isn't specified to take a double-pointer.

But if that were the case, it shouldn't even be working on OS X...

Also, try removing the 'static' declaration on the function. It isn't truly necessary, and may give the compiler room to optimize that function out of existence.
Quote this message in a reply
Member
Posts: 22
Joined: 2006.04
Post: #5
I tried it with and without the & - no joy. If I remove the static declaration then display becomes a normal instance member function of a c++ class and requires an implicit this pointer - not compatible with the normal c function pointer required by GLUT (I think that's the explanation).

I tried moving the order in which I register the callbacks and initiate GLUT - I can swap between windowed and full screen and all sorts on macos now no problem, but instead of the error I had before in Windows I crash my video card driver horribly.

Thanks for the help - I think I may insist on demoing on a mac and try and sort this out later.

Flash!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Windows has a few different function calling conventions, I suppose it's possible that the one glutDisplayFunc expects is not the same as the one that your static method is using... does your project compile without warning?
Quote this message in a reply
Member
Posts: 22
Joined: 2006.04
Post: #7
Yes, it did (at least for that line of code). I changed the order the callbacks are set up for the benefit of the Mac version and now the Windows one crashes my video driver on start up instead of the exception I had before :s
It seems to me that GLUT on windows may be flakier than on macos - i'm also wishing I'd installed gcc instead of using MS Visual C++, but I thought it made sense to use the closest compiler I could get to the one in our labs.
I'm going to try the current version in the lab tomorrow morning before the demo - the driver there may not crash I suppose.

Flash!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  pls help ....am in desperate need of code (illuminating equation) shru_ani 2 2,212 Oct 30, 2006 04:32 PM
Last Post: Najdorf