[SDL] RE: Parashute

Joseph Carter knghtbrd at bluecherry.net
Mon Jul 22 20:10:01 PDT 2002


On Tue, Jul 23, 2002 at 08:16:12AM +0600, alteest wrote:
> i have some troubble:
> when i try do something with
> 
> SDL_Surface *screen;
> 
> after intialization and create main window (it's ok), later (something other
> with "screen") i resieve:
> 
> "Fatal signal Segmentation Fault (SDL Parashute Deployed)"
> 
> i can't do anything with "screen". i download last sdl libs - nothing.
> what to do?

Yes, no wonder looking at your code.  Corrections below:

> #include "sdl.h"
> 
> int fullscreen = 0;
> 
  /* This should return the surface you allocate */
  SDL_Surface *CreateServerWindow(char* title, int width, int height,
  		int bits, BOOL fullscreenflag)
> {
        SDL_Surface *screen;
> 	Uint32 flags;
> 	flags = SDL_HWSURFACE|SDL_DOUBLEBUF; // I tried with different flags
> 	if ( fullscreenflag )
> 		flags |= SDL_FULLSCREEN;
	screen = SDL_SetVideoMode(width, height, bits, flags);
	if ( screen != NULL )
		SDL_WM_SetCaption(title, NULL);
	return screen;
> }
> 
> 
> BOOL SetWindowWhite(SDL_Surface *screen)
> {
> 	SDL_Rect rect;
> 	rect.x = 20;
> 	rect.y = 20;
> 	rect.w = 50;
> 	rect.h = 50;
> 	Uint32 white;
> 	SDL_PixelFormat *frmt;
> 	.
> 	.
> 	if ( SDL_MUSTLOCK(screen) ) {
> 		if ( SDL_LockSurface(screen) < 0 ) { // HERE IS GOES IN ERROR
> 			fprintf(stderr, "Can't lock screen: %s\n", SDL_GetError());
> 			return FALSE;
> 		}
> 	}
> 	.
> 	.
>     return TRUE;
> }
> 
  /* We need to actually set screen to something */
> void SDLInit()
> {
> 	int i, done;
> 	SDL_Event event;
> 	SDL_Surface *screen;
> 
> 	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
> 		fprintf(stderr, "Couldn't initialize SDL; %s\n", SDL_GetError());
> 		exit(1);
> 	}
> 	atexit(SDL_Quit);
	screen = CreateServerWindow("server", 640, 480, 16, fullscreen);
 	if (screen == NULL) {
> 		fprintf(stderr, "Couldn.t set 640x480x16 video mode: %s\n", SDL_GetError);
> 		SDL_Quit();
> 		exit(1);
> 	}
> 	if (!SetWindowWhite(screen))
> 		exit(1);
> 	done = 0;
> 	while (!done) {
> 		while(SDL_PollEvent(&event)) {
> 			if (event.type == SDL_QUIT)
> 				done = 1;
> 			if (event.type == SDL_KEYDOWN)
> 				if (event.key.keysym.sym == SDLK_SPACE) {
> 					done = 1;
> 				}
> 		}
> 	}
> 	SDL_Quit();
> }

The problem is that you weren't actually setting screen to anything, ever.
So I just made sure it was set and returned from your init function.  This
should work, probably.

-- 
Joseph Carter <knghtbrd at bluecherry.net>     I N33D MY G4M3Z, D00D!!!!111!!
                                                      (Just ... don't ask)
 
I sat laughing snidely into my notebook until they showed me a PC running
Linux. And oh! It was as though the heavens opened and God handed down a
client-side OS so beautiful, so graceful, and so elegant that a million
Microsoft developers couldn't have invented it even if they had a hundred
years and a thousand crates of Jolt cola.
        -- LAN Times

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020722/011ed723/attachment-0008.pgp>


More information about the SDL mailing list