SDL/OpenGl seg fault help.

This is a discussion on SDL/OpenGl seg fault help. within the Game Programming forums, part of the General Programming Boards category; Registered new type: STL Vector Setting breakpoints Debugger name and version: GNU gdb 6.7.50.20071127 Child process PID: 2780 Program received ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    89

    SDL/OpenGl seg fault help.

    Registered new type: STL Vector
    Setting breakpoints
    Debugger name and version: GNU gdb 6.7.50.20071127
    Child process PID: 2780
    Program received signal SIGSEGV, Segmentation fault.
    In SDL_GL_SwapBuffers () (C:\Documents and Settings\Public\My Documents\NewSDL_PROJECT\SDL.dll)


    apparently from what I can tell is that the problem lies in SDL_GL_SwapBuffers(). But that cant be right...can it?

    the program runs just fine...its just when I try exit that it faults on me.

    http://members.gamedev.net/ridejocka...DL_PROJECT.zip
    Last edited by eaane74; 07-11-2008 at 10:36 AM. Reason: added link

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    The problem is that you call SDL_Quit() when escape is pressed. Then your loop
    Code:
        while(m_Running)
        {
            while(SDL_PollEvent(&event))
            {
                OnEvent(&event);
            }
    
            OnLoop();
    
            glClear(GL_COLOR_BUFFER_BIT);
    
            OnRender();
    
            SDL_GL_SwapBuffers();
        }
    goes on to execute SDL functions (i.e. SDL_GL_SwapBuffers()), which won't work after you've called SDL_Quit().

    So, here's what I suggest you do. Instead of calling SDL_Quit(), use
    Code:
    m_Running = 0;
    I'd then follow your logic to make sure SDL_Quit() is called eventually.

    I compiled and ran your project under Linux with no troubles, in case you're interested about portability.

    BTW, please put a default case where you switch on an SDLKey -- with warnings enabled, you get hundreds of warnings about unhandled enumeration values . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    89
    thanks....I was beating my head against the wall trying to figure that one out. It had me completely stumped.

    I was going to as about the enumeration warnings. I thought it was because I was using a switch statement instead of if else statements. It is pretty annoying when your compiler goes through about 300 warnings every time you recompile the project.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > It is pretty annoying when your compiler goes through about 300 warnings every time you recompile the project.
    So fix them all then!
    Then when you get 1 new warning (when you previously had zero), you'll be able to see it instantly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    It's very easy to fix. As I mentioned, you just need to put
    Code:
    default:
        break;
    where ever you switch on an enum. I think that only occurs in one place, where you switch() on an SDLKey.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting a seg fault
    By ammochck21 in forum C Programming
    Replies: 11
    Last Post: 01-23-2009, 04:27 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  4. weird seg fault
    By Vermelho in forum C Programming
    Replies: 3
    Last Post: 05-10-2008, 08:27 PM
  5. Seg Fault Problem
    By ChazWest in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2002, 03:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21