Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

unusual error with same code on different systems.--Function <glutBitmapCharacter> called without first calling 'glutInit'

231 views
Skip to first unread message

ashjas

unread,
Mar 2, 2008, 12:07:53 AM3/2/08
to
Hello,
when i try to execute a code,i get this error

freeglut ERROR: Function <glutBitmapCharacter> called without first
calling 'glutInit'.

the thing of concern is that the same code runs fine on one system
with RHEL4 and on the other with RHEL4 the same error comes...

on ubuntu at home i too get the same error...

the much more amazing thing is that when this code runs fine on a
system,
the output at terminal is::
HIHIHIHIHIHI

pID zero 0
pID not zero 15640

which means the control goes in both parts,the if part and the else
part....How can this be possible???

Secondly,on systems on which this code doesnt run,if i comment out all
the lines that use the glutBitmapCharacter function....the code runs
fine on them aswell but this isnt a solution at all...because the
"glutinit not called first" error should come here aswell as other
glut functions are being still used(if the compiler is fair
enough)...and as one can see the glutInit function is being called at
the right place in the main function..

Does anyone have any clue about this??

Help is appreciated.

Thanks,
Regards.

here is the main() code:::

##########################################

int main (int argc, char** argv)
{
cout<<"\n\nHIHIHIHIHIHI\n\n";
int stat=0;
int b;
pid_t pID;


pID = fork();

if(pID==0){
printf("pID zero %d\n",pID);
execl("/bin/sh","/bin/sh","-c","./noutput",0);
#ifdef __abc__
execl("/usr/bin/bash","/usr/bin/bash","-c","./noutput",0);
#else
execl("/bin/bash","/bin/bash","-c","./noutput",0);
#endif

}

else if(pID>0){
printf("pID not zero %d\n",pID);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);


glutInitWindowSize(1600,1200);
glutInitWindowPosition(0,0);

glutCreateWindow();


init();
createMenu();

glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(display);


glutKeyboardFunc(sampleKeyFunc);
glutMouseFunc(mouseClick);
glutMotionFunc(mouseMoveActive);
glutPassiveMotionFunc(mouseMovePassive);
glutMainLoop();


}
else
printf("error in child process");

return 0;
}
##########################################

Dave Eberly

unread,
Mar 2, 2008, 2:46:11 AM3/2/08
to
"ashjas" <ash...@gmail.com> wrote in message
news:98253d11-a550-4a28...@e23g2000prf.googlegroups.com...

> pID zero 0
> pID not zero 15640
>
> which means the control goes in both parts,the if part and the else
> part....How can this be possible???

Well, you did call "fork()".
http://www.opengroup.org/onlinepubs/000095399/functions/fork.html
Note "The child process shall have a unique process ID".

--
Dave Eberly
http://www.geometrictools.com


fungus

unread,
Mar 2, 2008, 5:40:54 AM3/2/08
to
On Mar 2, 6:07 am, ashjas <ash...@gmail.com> wrote:
>
> pID = fork();
>

Are you sure you know what this does...?

--
<\___/>
/ O O \
\_____/ FTB. Remove my socks for email address.


ashjas

unread,
Mar 2, 2008, 6:47:15 AM3/2/08
to
On Mar 2, 12:46 pm, "Dave Eberly" <dNOSPAMebe...@usemydomain.com>
wrote:

yes...rightly said it has to go in both the if and the else part...

but any clue about the error thats coming when executable is run.....
and when run....no printfs are shown only runtime error as:


freeglut ERROR: Function <glutBitmapCharacter> called without first


So dows this mean that the control isnt going to main() even??
then how come at runtime it comes to know that glutBitmapCharacter is
being called without glutInit()..which is not actually right as it is
being called.. and all the rendering is done only after the glutInit
and glut modes..etc are set....

from where is this error coming...

every other program in opengl is running fine though..

thanks.

fungus

unread,
Mar 2, 2008, 8:52:21 AM3/2/08
to
On Mar 2, 12:47 pm, ashjas <ash...@gmail.com> wrote:
>
> from where is this error coming...
>

Somewhere deep in the system.

What happens if you swap the sense of the fork around
(ie. do the GLUT stuff in the pid==0 branch).

Dave Eberly

unread,
Mar 2, 2008, 11:52:51 AM3/2/08
to

"ashjas" <ash...@gmail.com> wrote in message
news:8e3cc615-e38e-4760...@d4g2000prg.googlegroups.com...

> but any clue about the error thats coming when executable is run.....
> and when run....no printfs are shown only runtime error as:
> freeglut ERROR: Function <glutBitmapCharacter> called without first

Have you tried running through a debugger and setting breakpoints at
the call to glutInit and at the call to glutBitmapCharacter? Given that
you are forking the process, there might be a sequencing issue.

Wolfgang Draxinger

unread,
Mar 2, 2008, 1:32:59 PM3/2/08
to
ashjas wrote:

Why are you doing that? If the user wants the program to not to
block the shell, he will start it in background (append a '&')
after the command line.

If you're anxious that the user might kill the shell or close the
terminal, but you want the program not to be terminated, supply
a signal handler for SIGHUP. Or start the programm
through "nohup".

Wolfgang Draxinger
--
E-Mail address works, Jabber: hexa...@jabber.org, ICQ: 134682867

ashjas

unread,
Mar 13, 2008, 1:11:45 PM3/13/08
to
On Mar 2, 11:32 pm, Wolfgang Draxinger <wdraxin...@darkstargames.de>
wrote:
> E-Mail address works, Jabber: hexar...@jabber.org, ICQ: 134682867

Well....I have sorted the problem that I posted here.....

In my program,I was creating a global object whose constructor was
calling a function that was calling in turn the glutBitmapCharacter
function.
when i commented out that function call from the constructor...all
went well and fine...

Maybe this solution can prove helpful to others...

Thanks to all,for giving inputs..

Bye.

0 new messages