Results 1 to 4 of 4

Thread: Glut+subwindow+Scroll Mouse = Segmentation fault

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2005
    Location
    WY
    Posts
    2

    Glut+subwindow+Scroll Mouse = Segmentation fault

    Hi,

    I meet the problem when I use scroll mouse in the subwindow created by glut. When I scroll up the scroll button, code crash. Other mouse buttons have no problem. Scroll down the scroll button has no problem too. If you run the attached code, move mouse to the center and scroll up the mouse, you will know what I mean.

    I don't know whether it is a bug of glut or not. Does anyone know how to fix this problem?

    Thanks.

    -------------------------------------------------
    //
    //gcc -O3 -o mouse mouse.c -L/usr/X11R6/lib -lGL -lGLU -lX11 -lglut -lXmu
    //
    #include <GL/glut.h>
    #include <stdlib.h>

    static GLfloat spin = 0.0;

    void display(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glRotatef(spin, 0.0, 0.0, 1.0);
    glColor3f(0.0, 1.0, 0.0);
    glRectf(-0.5, -0.5, 0.5, 0.5);
    glPopMatrix();

    glutSwapBuffers();
    }

    void mdisplay(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0);
    glRectf(-40.0, -40.0, 40.0, 40.0);

    glutSwapBuffers();
    }

    void spinDisplay(void)
    {
    spin = spin + 2.0;
    if (spin > 360.0)
    spin = spin - 360.0;
    glutPostRedisplay();
    }

    void reshape(int w, int h)
    {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }

    void mouse(int button, int state, int x, int y)
    {
    switch (button) {
    case GLUT_LEFT_BUTTON:
    if (state == GLUT_DOWN)
    glutIdleFunc(spinDisplay);
    break;
    case GLUT_MIDDLE_BUTTON:
    if (state == GLUT_DOWN)
    glutIdleFunc(NULL);
    break;
    default:
    break;
    }
    }

    int subwin(int mwin)
    {
    int swin;

    swin = glutCreateSubWindow (mwin,50,50,150,150);

    glClearColor (0.0, 0.0, 1.0, 0.0);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    return 0;
    }

    int mainwin()
    {
    int mwin;

    glutInitWindowSize (250, 250);
    glutInitWindowPosition (100, 100);

    mwin = glutCreateWindow ("main");
    glClearColor (0.0, 0.0, 0.0, 0.0);

    glutDisplayFunc(mdisplay);
    glutReshapeFunc(reshape);

    return mwin;
    }

    int main(int argc, char** argv)
    {
    int mwin,swin;

    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);

    mwin = mainwin();

    subwin(mwin);

    glutMainLoop();
    return 0;
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2005
    Posts
    145

    Re: Glut+subwindow+Scroll Mouse = Segmentation fault

    Looks OK to me. Have you tried using a dummy idle func instead of passing NULL to glutIdleFunc? In Windows this is not a problem, but I don't know about Linux.

    Hlz

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2005
    Location
    WY
    Posts
    2

    Re: Glut+subwindow+Scroll Mouse = Segmentation fault

    Even I delete everything in function "mouse", the code will crash if I use scroll up the scroll button, which is button = 3.(the callback of left button=0, right button=1, middle/scroll button=2, scroll up middle button=3, scroll down middle button = 4).

    If there is no subwindow, the code will not crash for any buttons.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Aug 2005
    Posts
    145

    Re: Glut+subwindow+Scroll Mouse = Segmentation fault

    That's freaky.

    I hate to say bug, until I've exhausted everything, but it sure looks like one here, somewhere. I just ran it on my Wintel box and it's fine...

    P.S. What's the debugger telling you, if anything?

Similar Threads

  1. Segmentation fault with cl2.hpp
    By Mike Zhang in forum OpenCL
    Replies: 0
    Last Post: 02-03-2017, 12:22 AM
  2. Segmentation fault
    By SagoO in forum OpenGL: Basic Coding
    Replies: 28
    Last Post: 01-12-2011, 09:45 AM
  3. Segmentation fault
    By kmn2446 in forum OpenGL: Linux
    Replies: 4
    Last Post: 03-16-2004, 08:53 AM
  4. glut and mouse wheel gives segmentation fault
    By IndianRopeMan in forum OpenGL: Linux
    Replies: 4
    Last Post: 09-03-2003, 09:35 PM
  5. glut and mouse wheel gives segmentation fault
    By IndianRopeMan in forum OpenGL: User Software
    Replies: 1
    Last Post: 08-23-2003, 03:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean