App causes whole machine to hang/crash

Hi.
I posted this in the toolkit area, but there’s about 1 post per day there, so thought I’d try my luck here …

I’ve been having this problem since I’ve started programming in openGL with (free/open)GLUT (I’ve tried both). I have also tested this problem with SDL and I get the same result.

What’s happening is if I draw anything using glut’s idleFunc callback (or the relative similar coding for SDL), everything runs fine until I move the mouse to the titlebar (after a few seconds of running)… any part of the title bar. The entire machine hangs, getting stuck in some kind of unbreakable loop, making the system completely unusuable to the point where a cold boot is necessary.

I’m running under Fedora Core 3 with Gnome/enlightenment, don’t know if it has anything to do with that.

If I set the rendering callback to the TimerFunc and have it call every say, 4ms, everything runs fine, and I would Assume that if I put some kind of sleep call in the render function things would work fine as well, but I’m learning, and I want to learn how to do things correctly, ya know?

Anyone have any ideas?

Your problem comes from an incorrect use of glut I guess. Don’t do any timer function callback with the display function !!

glutDisplayFunc (display);
glutIdleFunc (idle);

where display() is the function where you draw and idle func generally only implement a call to glutPostRedisplay();
Timer function callback should not be the display. Only implement the ‘background’ on them, like changing the direction, the view and so on.

If I’m wrong, I ask for you to post your code or give a link to it.

Hope that helps.

Originally posted by jbich:
[b]Hi.
I posted this in the toolkit area, but there’s about 1 post per day there, so thought I’d try my luck here …

I’ve been having this problem since I’ve started programming in openGL with (free/open)GLUT (I’ve tried both). I have also tested this problem with SDL and I get the same result.

What’s happening is if I draw anything using glut’s idleFunc callback (or the relative similar coding for SDL), everything runs fine until I move the mouse to the titlebar (after a few seconds of running)… any part of the title bar. The entire machine hangs, getting stuck in some kind of unbreakable loop, making the system completely unusuable to the point where a cold boot is necessary.

I’m running under Fedora Core 3 with Gnome/enlightenment, don’t know if it has anything to do with that.

If I set the rendering callback to the TimerFunc and have it call every say, 4ms, everything runs fine, and I would Assume that if I put some kind of sleep call in the render function things would work fine as well, but I’m learning, and I want to learn how to do things correctly, ya know?

Anyone have any ideas?[/b]
Hello there,
Strange indeed. Hey are you using double buffering if so then see if you are swapping the buffers. Also have a look t your code to see any illegal ponter referencing that normally causes crashes. See if this sorts out your problem
Thanx
MMM

Thanks for the reponses :slight_smile:

Jide: Every tutorial I’ve seen uses IdleFunc to draw the scene. The only reason I used the timercallback was to reduce the amount of drawing occuring to let the computer catch it’s breath.

MMMovania: I am using double buffering and I am swapping the buffers, if you don’t, it doesn’t render pretty much at all … lol :slight_smile:

I was trying to avoid you guys having to pour through poor code, but I guess it’s sort of unavoidable :frowning:

I stripped everything down so here’s the nutshell of the code I’m trying to implement. It may not compile correctly, as I’m just cutting and pasting the important code, but this is pretty much what I’m doing:

---------------- Code
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>

float cubeAngleX = 0;
float cubeAngleY = 0;

void render(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

glRotatef(cubeAngleX, 1.0, 0.0, 0.0);
glRotatef(cubeAngleY, 0.0, 1.0, 0.0);

glBegin(GL_QUADS);
/* Front Face */
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(-1.0,-1.0, 1.0);
glVertex3f( 1.0,-1.0, 1.0);
glVertex3f( 1.0, 1.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);

/* Back Face */
glNormal3f(0.0, 0.0,-1.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f( 1.0,-1.0,-1.0);
glVertex3f( 1.0, 1.0,-1.0);
glVertex3f(-1.0, 1.0,-1.0);

/* Bottom Face */
glNormal3f(0.0,-1.0, 0.0);
glVertex3f(-1.0,-1.0, 1.0);
glVertex3f( 1.0,-1.0, 1.0);
glVertex3f( 1.0,-1.0,-1.0);
glVertex3f(-1.0,-1.0,-1.0);

/* Top Face */
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-1.0, 1.0,-1.0);
glVertex3f( 1.0, 1.0,-1.0);
glVertex3f( 1.0, 1.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);

/* Right Face */
glNormal3f(1.0, 0.0, 0.0);
glVertex3f( 1.0,-1.0, 1.0);
glVertex3f( 1.0,-1.0,-1.0);
glVertex3f( 1.0, 1.0,-1.0);
glVertex3f( 1.0, 1.0, 1.0);

/* Left Face */
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f(-1.0,-1.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(-1.0, 1.0,-1.0);

glEnd();

cubeAngleX++;
cubeAngleY++;

glutSwapBuffers();
}

int init(int w, int h){
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window
glMatrixMode(GL_MODELVIEW);
return 1;
}

void timerCallback(int value){
render();
glutTimerFunc(4, timerCallback, 1);
}

void resizeCallback(int w, int h){
if(!h){ h = 1; }
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(250, 250);
glutCreateWindow(“3d Cube with Texture”);
/
glutDisplayFunc(render); I tried turning this off to see if it would effect the crash, but it doesn’t seem to /
/
glutIdleFunc(render); This causes the machine to halt after a few seconds if you put your mouse over the window border and cause a Window Event
/
glutTimerFunc(1, timerCallback, 1); /* Start the timer */
glutReshapeFunc(resizeCallback);
if(!init(250, 250)){ exit(1); }
glutMainLoop();
return 0;
}

Oh…
I’m a dork. I forgot to mention:

The code I supplied works correctly when I use only the TimerFunc to render the scene. When I use the idleFunc I do NOT use the timerFunc at the same time, I use one OR the other … so that’s not the problem lol…

Just thought I’d mention that as the code I supplied might be misleading …

Here is how it should have to be done, and you were right about PostRedisplay (I merge several things on this moment).

void render()
{
// your rendering code
}

void idle()
{
   glutPostRedisplay();
   // generally nothing else is needed
}

glutDisplayFunc (render);
glutIdleFunc (idle);

Note that idle func is not calling render.
I’m sure this will work fine like that.

I thank you for your response and help Jide.

Unfortunately, that didn’t solve the problem :frowning:

Did the exact same thing it always does. Runs well for a few seconds, then if you move the mouse over the titlebar, hangs the whole computer /cry

Any other ideas?

Man, I’d really like to dive into some deeper code and learn more opengl, but it doesn’t make sense to me to build a house on a broken foundation… ya know? sniff

So it seems to be another problem. Maybe an issue with what you have on your machine. It doesn’t seem to be a gl problem, but surely a X11 one.

Did you try little gl demos like glxgears ?

Does your issue happen both on gnome and enlightenment ? Did you tried xdm instead of gdm ?
What X11 do you have (XFree or xorg) ? Did you compile glut yourself ?

Lots of information will be best.

Also this post seems to be best on the linux forum now, but we might keep it to avoid redundancies.

Um… :slight_smile:
Ok. I posted here because the linux forum doesn’t seem that busy. If I was out of line I apologise.

Gnome runs with enlightenment, at the same time, so yeah it’s happening with that combo. I’ve also tried it on my laptop which is running FC3 with gnome and sawfish. Same result.
FC3 comes with xorg. I can’t imagine the graphical login manager being an issue, but I’m running gdm.

I used the FC3 RPM when I was trying freeglut, but I moved on to openglut (which I compiled myself) which does seem to work better.

I haven’t tried the demos, I will do so as soon as I can close some of these windows I’m working in (I’m at work) and am in a good spot to be able to reboot a lot lol.

At least I feel better knowing I’m not a total retard and perhaps this is a bit beyond my knack for doing incredibly stupid things sometimes :wink:

So this happens even if you don’t use enlightenemnt, and whether you use gnome or anything else.

I really think this is an issue from the window manager because there’s not only one desktop that provokes the errors. If only E made those badnesses, then I wouldn’t have thought this was X11. But as any desktops made this error.
I also cannot think this is due to glut just because this happens on the window decoration, which has nothing to do with glut but more X11 and/or the desktops.

Finally, when you say “I used the FC3 RPM when I was trying freeglut, but I moved on to openglut (which I compiled myself) which does seem to work better.”, does it means openglut doesn’t provoke the errors you mentioned ? Or am I misinterpreting what you wrote ?

I agree, I think it might be something along the lines of X itself somewhere.

Openglut causes the same problems as freeglut and SDL, it just seemed to run some of the other glitches (which aren’t related or relevant to the current conversation) a little better.

I guess I’ll try a few things. Do some nosing around and a whole lot of reboots.

I’ll post anything if I find a cause.

Thanks so much for your help.
Of course, if you happen to think of anything please let me know.

Also, the reshape callback gets called in the beginning, so it’s not necessary to set up your projection in init(); Try to find the glut pdf and read the beginning. It should provide some good hints

Thanks.
I have and have read the glut pdf all the way through a few times now.

I’ll take that out, but I’m mainly concerned with why my whole system is halting.

Redhat seems to be absolutely no help. I opened a bug, but they don’t want to help or even hear of it.

Hi guys.
Wanted to let you know I finally resolved this issue.

I’ve posted a quick description and explination on how to fix the problem in the linux section.

Linux Hangups Solved

Thanks so much for all your help and patience!

j