Thread: SDL segfault when trying to draw to screen

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    SDL segfault when trying to draw to screen

    Code:
    if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
    	{
    		printf("Unable to init SDL: %s\n", SDL_GetError());
    		exit(1);
    	}
    	atexit(SDL_Quit);
    	screen=SDL_SetVideoMode(1024,768,32,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
    	if ( screen == NULL )
    	{
    		printf("Unable to set video: %s\n", SDL_GetError());
    		exit(1);
    	}
    	
    	drawString(screen, font, 0, 0, "Loaded!\n");
    It Segfaults at the drawString.

    I've tried blitting surfaces to the screen and all, but it still segfaults whenever I try to draw to the screen.
    This war, like the next war, is a war to end war.

  2. #2
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373
    I fixed it. It semms i wasn't initializeing certain objects.
    This war, like the next war, is a war to end war.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You need to lock/unlcok a surface before using it.
    Code:
    void render()
    {   
     
     // Lock surface if needed
      if (SDL_MUSTLOCK(Screen))
        if (SDL_LockSurface(Screen) < 0) 
          return;
    
      //draw to screen here
    
      // Unlock if needed
        if (SDL_MUSTLOCK(Screen)) 
            SDL_UnlockSurface(Screen);
    
      // Tell SDL to update the whole gScreen
        SDL_UpdateRect(Screen, 0, 0, WIDTH, HEIGHT);    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sdl screen resize and redraw problem
    By mad_muppet in forum Game Programming
    Replies: 1
    Last Post: 08-09-2008, 08:55 PM
  2. SDL + Keys
    By Livijn in forum Game Programming
    Replies: 24
    Last Post: 05-11-2007, 04:31 PM
  3. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  5. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM