• Lucid Dreaming - Dream Views




    Results 1 to 5 of 5

    Thread: glut help?

    1. #1
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935

      glut help?

      I don't understand why this code is failing. It doesn't display the menu, but the cursor changes as if it was there. Then it crashes and prints out that it encountered a segmentation fault and did a core dump.

      Code:
      static unsigned short daynight = 0;
      
      void DayorNight(int choice){
          daynight = (choice - 1) * 50;  //either 0 or 50
      }
      
      int main (int argc, char** argv){
          glutInit (&argc, argv);
          glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGB);
          glutInitWindowSize (800, 600);
          glutInitWindowPosition (0, 0);
          glutCreateWindow (argv[0]);
          init ();
          glutReshapeFunc (reshape);
          glutDisplayFunc (display);
          glutIdleFunc(animate);
          glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          glutMouseFunc(checkmouse);
          InitializeCars();
      
      //problematic code?
      
          glutCreateMenu(DayorNight);
          glutAddMenuEntry("Night", 1);
          glutAddMenuEntry("Day", 2);
          glutAttachMenu(GLUT_RIGHT_BUTTON);
          
      //
      
          //set up the timers
          seekchange = clock() + 150000;
          ResetTime = clock() + 33;  //should be 30FPS
          glutMainLoop ();
          return 0;
      }
      It's C if that's not obvious and everything else works until I right click on the screen.

    2. #2
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      never used glut
      but just looking at it, try
      changing "static unsigned short daynight" to "static int daynight"
      and making your DayorNight function static
      (\_ _/)
      (='.'=)
      (")_(")

    3. #3
      Member Achievements:
      1 year registered Veteran First Class 5000 Hall Points

      Join Date
      Sep 2004
      Gender
      Location
      Seattle, WA
      Posts
      2,503
      Likes
      217
      Run a debugger on the core dump and binary and show us what your stack trace looks like.

    4. #4
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Umm... How do I go about doing that? I'm not using an IDE, I'm compiling from the command line.

    5. #5
      Member Achievements:
      1 year registered Veteran First Class 5000 Hall Points

      Join Date
      Sep 2004
      Gender
      Location
      Seattle, WA
      Posts
      2,503
      Likes
      217
      GDB is a command line debugger. Google GDB tutorial. Here's a sample run:

      Code:
      ~/sandbox/foo/$ cat > test.cpp
      int main(void) {
          int x = 5, y = 0;
          int z = x/y;
          return 0;
      }
      
      ~/sandbox/foo/$ g++ -g -o test test.cpp
      
      ~/sandbox/foo/$ gdb test
      GNU gdb Red Hat Linux (6.3.0.0-1.132.EL3rh)
      Copyright 2004 Free Software Foundation, Inc.
      GDB is free software, covered by the GNU General Public License, and you are
      welcome to change it and/or distribute copies of it under certain conditions.
      Type "show copying" to see the conditions.
      There is absolutely no warranty for GDB.  Type "show warranty" for details.
      This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
      
      (gdb) run
      Starting program: /home/xxxxx/sandbox/foo/test
      
      Program received signal SIGFPE, Arithmetic exception.
      0x08048384 in main () at test.cpp:3
      3           int z = x/y;
      (gdb) quit
      The program is running.  Exit anyway? (y or n) y
      
      ~/sandbox/foo/$
      You can also specify a core file with the binary, and it will just tell you where it failed. From the GDB man page:

      You can also start with both an executable program and a core file
      specified:

      gdb program core
      Hope this helps. If you're going to be using OpenGL or doing anything beyond some silly single-file exercise, you really need to learn to use a debugger anyway (and while gdb isn't really the easiest to use, it's a good learning tool).

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •