SDL fullscreen problem

When I run a program in X system on F7 ,the X crashed ,just like I press
CTRL+ALT+BACKSPACE.
It is sure that the code has no problem,I get it from linux game programming.
What’s the problem?

the code is below,

#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
Uint16 CreateHicolorPixel(SDL_PixelFormat * fmt, Uint8 red,
Uint8 green, Uint8 blue)
{
Uint16 value;
value = ((red >> fmt->Rloss) << fmt->Rshift) +
((green >> fmt->Gloss) << fmt->Gshift) +
((blue >> fmt->Bloss) << fmt->Bshift);
return value;
}
int main()
{
SDL_Surface *screen;
Uint16 *raw_pixels;
int x, y;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(256, 256, 24, SDL_FULLSCREEN|SDL_SWSURFACE);
if (screen == NULL) {
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}
SDL_LockSurface(screen);
raw_pixels = (Uint16 *) screen->pixels;
for (x = 0; x < 256; x++) {
for (y = 0; y < 256; y++) {
Uint16 pixel_color;
int offset;
pixel_color = CreateHicolorPixel(screen->format,
x, 0, y);
offset = (screen->pitch / 2 * y + x);
raw_pixels[offset] = pixel_color;
}
}
SDL_UnlockSurface(screen);
SDL_UpdateRect(screen, 10, 10, 200, 120);
SDL_Delay(3000);
return 0;
}

Any one can help me?

cocobear wrote:>

When I run a program in X system on F7 ,the X crashed ,just like I press
CTRL+ALT+BACKSPACE.
It is sure that the code has no problem,I get it from linux game
programming.
What’s the problem?

the code is below,

#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
Uint16 CreateHicolorPixel(SDL_PixelFormat * fmt, Uint8 red,
Uint8 green, Uint8 blue)
{
Uint16 value;
value = ((red >> fmt->Rloss) << fmt->Rshift) +
((green >> fmt->Gloss) << fmt->Gshift) +
((blue >> fmt->Bloss) << fmt->Bshift);
return value;
}
int main()
{
SDL_Surface *screen;
Uint16 *raw_pixels;
int x, y;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(256, 256, 24, SDL_FULLSCREEN|SDL_SWSURFACE);
if (screen == NULL) {
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}
SDL_LockSurface(screen);
raw_pixels = (Uint16 *) screen->pixels;
for (x = 0; x < 256; x++) {
for (y = 0; y < 256; y++) {
Uint16 pixel_color;
int offset;
pixel_color = CreateHicolorPixel(screen->format,
x, 0, y);
offset = (screen->pitch / 2 * y + x);
raw_pixels[offset] = pixel_color;
}
}
SDL_UnlockSurface(screen);
SDL_UpdateRect(screen, 10, 10, 200, 120);
SDL_Delay(3000);
return 0;
}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


View this message in context: http://www.nabble.com/SDL-fullscreen-problem-tf4370363.html#a12471881
Sent from the SDL mailing list archive at Nabble.com.

Hello !

When I run a program in X system on F7 ,the X crashed ,just like I
press
CTRL+ALT+BACKSPACE.
It is sure that the code has no problem,I get it from linux game
programming.
What’s the problem?

the code is below,

#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>

Use #include “SDL.h” and use it after stdio.h and stdlib.h

Uint16 CreateHicolorPixel(SDL_PixelFormat * fmt, Uint8 red,
Uint8 green, Uint8 blue)
{
Uint16 value;

You use Uint16 but you are running with SDL_SetVideoMode (…,24,…)
so better use a Uint32 for pixel values.

value = ((red >> fmt->Rloss) << fmt->Rshift) +
        ((green >> fmt->Gloss) << fmt->Gshift) +
        ((blue >> fmt->Bloss) << fmt->Bshift);
return value;

}

Better use the SetPixel function from the SDL website.

int main()

To be portable do int main(int argc, char *argv [])

{
SDL_Surface *screen;
Uint16 *raw_pixels;
int x, y;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(256, 256, 24,
SDL_FULLSCREEN|SDL_SWSURFACE);
if (screen == NULL) {
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}

Do an if SDL_MUSTLOCK (screen) true then only lock the surface.

SDL_LockSurface(screen);
raw_pixels = (Uint16 *) screen->pixels;
for (x = 0; x < 256; x++) {
for (y = 0; y < 256; y++) {
Uint16 pixel_color;
int offset;
pixel_color = CreateHicolorPixel(screen->format,
x, 0, y);
offset = (screen->pitch / 2 * y + x);
raw_pixels[offset] = pixel_color;
}
}
SDL_UnlockSurface(screen);

The same with SDL_MUSTLOCK as above

SDL_UpdateRect(screen, 10, 10, 200, 120);
SDL_Delay(3000);
return 0;

}

CU

? Tue, 4 Sep 2007 10:35:08 +0200 (CEST)
“Torsten Giebl” ??:

Hello !

When I run a program in X system on F7 ,the X crashed ,just like I
press
CTRL+ALT+BACKSPACE.
It is sure that the code has no problem,I get it from linux game
programming.
What’s the problem?

the code is below,

#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>

Use #include “SDL.h” and use it after stdio.h and stdlib.h

I should use #include “SDL/SDL.h”,because if I use “SDL.h”,the GCC
could’t find SDL.h
My SDL.h is in /usr/include/SDL/SDL.h

Uint16 CreateHicolorPixel(SDL_PixelFormat * fmt, Uint8 red,
Uint8 green, Uint8 blue)
{
Uint16 value;

You use Uint16 but you are running with SDL_SetVideoMode (…,24,…)
so better use a Uint32 for pixel values.

value = ((red >> fmt->Rloss) << fmt->Rshift) +
        ((green >> fmt->Gloss) << fmt->Gshift) +
        ((blue >> fmt->Bloss) << fmt->Bshift);
return value;

}

Better use the SetPixel function from the SDL website.

int main()

To be portable do int main(int argc, char *argv [])

Good advice.

{
SDL_Surface *screen;
Uint16 *raw_pixels;
int x, y;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(256, 256, 24,
SDL_FULLSCREEN|SDL_SWSURFACE);
if (screen == NULL) {
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}

Do an if SDL_MUSTLOCK (screen) true then only lock the surface.

SDL_LockSurface(screen);
raw_pixels = (Uint16 *) screen->pixels;
for (x = 0; x < 256; x++) {
for (y = 0; y < 256; y++) {
Uint16 pixel_color;
int offset;
pixel_color = CreateHicolorPixel(screen->format,
x, 0, y);
offset = (screen->pitch / 2 * y + x);
raw_pixels[offset] = pixel_color;
}
}
SDL_UnlockSurface(screen);

The same with SDL_MUSTLOCK as above

SDL_UpdateRect(screen, 10, 10, 200, 120);
SDL_Delay(3000);
return 0;

}

CU

Thanks for you reply,but the problem is when I set SDL to the
fullscreen mode , the X system will crashed. Even if I do nothing,just
set it fullscreen.

#include <stdlib.h>
#include “SDL/SDL.h”

int main(int argc, char* argv[])
{
SDL_Surface *screen;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN);
if (screen == NULL) {
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}
printf(“Success!\n”);
return 0;
}

When I run this simple code , the X crashed too!

Does it the bug of SDL?

My os is Fedora 7.

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/

El Martes 04 Septiembre 2007 16:01, cocobear escribi?:

I should use #include “SDL/SDL.h”,because if I use “SDL.h”,the GCC
could’t find SDL.h
My SDL.h is in /usr/include/SDL/SDL.h

No, you should use “SDL.h” only, because “sdl-config --cflags” gives

-I/usr/include/SDL

so GCC can find the header. You should then compile so:

gcc myfile.c sdl-config --cflags -c

? Tue, 4 Sep 2007 16:40:39 +0200
Alberto Luaces ??:

El Martes 04 Septiembre 2007 16:01, cocobear escribi?:

I should use #include “SDL/SDL.h”,because if I use “SDL.h”,the GCC
could’t find SDL.h
My SDL.h is in /usr/include/SDL/SDL.h

No, you should use “SDL.h” only, because “sdl-config --cflags” gives

-I/usr/include/SDL

so GCC can find the header. You should then compile so:

gcc myfile.c sdl-config --cflags -c

Oh,I know! Thanks a lot.
But my problem still not resolved.:frowning:

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/

? Tue, 4 Sep 2007 16:40:39 +0200
Alberto Luaces ??:

El Martes 04 Septiembre 2007 16:01, cocobear escribi?:

I should use #include “SDL/SDL.h”,because if I use “SDL.h”,the GCC
could’t find SDL.h
My SDL.h is in /usr/include/SDL/SDL.h

No, you should use “SDL.h” only, because “sdl-config --cflags” gives

-I/usr/include/SDL

so GCC can find the header. You should then compile so:

gcc myfile.c sdl-config --cflags -c


I find the problem!
When I try this code on my classmate’s computer ,and there’s no
problem,his OS also Fedora 7.

When I change video mode to 1024x768,it works. 1024x768 is my
resolution of X.

Is it bug of SDL or problem of my Video Card.
/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/

It’s a problem of your X server configuration I think. But I don’t
remember which parameter needs adjustement to fix the issue.On 9/4/07, cocobear <cocobear.cn at gmail.com> wrote:

? Tue, 4 Sep 2007 16:40:39 +0200
Alberto Luaces ??:

El Martes 04 Septiembre 2007 16:01, cocobear escribi?:

I should use #include “SDL/SDL.h”,because if I use “SDL.h”,the GCC
could’t find SDL.h
My SDL.h is in /usr/include/SDL/SDL.h

No, you should use “SDL.h” only, because “sdl-config --cflags” gives

-I/usr/include/SDL

so GCC can find the header. You should then compile so:

gcc myfile.c sdl-config --cflags -c


I find the problem!
When I try this code on my classmate’s computer ,and there’s no
problem,his OS also Fedora 7.

When I change video mode to 1024x768,it works. 1024x768 is my
resolution of X.

Is it bug of SDL or problem of my Video Card.
/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Olivier Delannoy
ATER
PRiSM Laboratory
Versailles University, FRANCE

El Martes 04 Septiembre 2007 17:27, escribi?:

? Tue, 4 Sep 2007 16:40:39 +0200

Alberto Luaces <@Alberto_Luaces_Ferna> ??:

El Martes 04 Septiembre 2007 16:01, cocobear escribi?:

I should use #include “SDL/SDL.h”,because if I use “SDL.h”,the GCC
could’t find SDL.h
My SDL.h is in /usr/include/SDL/SDL.h

No, you should use “SDL.h” only, because “sdl-config --cflags” gives

-I/usr/include/SDL

so GCC can find the header. You should then compile so:

gcc myfile.c sdl-config --cflags -c


I find the problem!
When I try this code on my classmate’s computer ,and there’s no
problem,his OS also Fedora 7.

When I change video mode to 1024x768,it works. 1024x768 is my
resolution of X.

Is it bug of SDL or problem of my Video Card.

I am wonder why SDL_SetVideoMode did not return NULL if the video mode you
were trying to set was not valid.

Try this:

  • On the console, type

ulimit -c unlimited

so when your program crashes we can get an stack trace.

  • Run your program from the console you typed that last command.
  • After the crash, check for a file named ‘core’.
  • Run the debugger:

gdb your_program core

the debugger stops the program at the point it crashed. Type:

bt

the content of the stack will be printed. Please send us that list.

? Tue, 4 Sep 2007 17:36:34 +0200
Alberto Luaces ??:

El Martes 04 Septiembre 2007 17:27, escribi?:

? Tue, 4 Sep 2007 16:40:39 +0200

Alberto Luaces ??:

El Martes 04 Septiembre 2007 16:01, cocobear escribi?:

I should use #include “SDL/SDL.h”,because if I use “SDL.h”,the
GCC could’t find SDL.h
My SDL.h is in /usr/include/SDL/SDL.h

No, you should use “SDL.h” only, because "sdl-config --cflags"
gives

-I/usr/include/SDL

so GCC can find the header. You should then compile so:

gcc myfile.c sdl-config --cflags -c


I find the problem!
When I try this code on my classmate’s computer ,and there’s no
problem,his OS also Fedora 7.

When I change video mode to 1024x768,it works. 1024x768 is my
resolution of X.

Is it bug of SDL or problem of my Video Card.

I am wonder why SDL_SetVideoMode did not return NULL if the video
mode you were trying to set was not valid.

Try this:

  • On the console, type

ulimit -c unlimited

so when your program crashes we can get an stack trace.

  • Run your program from the console you typed that last command.
  • After the crash, check for a file named ‘core’.

After I type ulimit -c unlimited ,I run the program,I didn’t got a file
named ‘core’.
Sorry for my poor english , maybe I am not understand you correctly.

  • Run the debugger:

gdb your_program core

the debugger stops the program at the point it crashed. Type:

bt

the content of the stack will be printed. Please send us that list.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/

After I type ulimit -c unlimited ,I run the program,I didn’t got a
file named ‘core’.
Sorry for my poor english , maybe I am not understand you correctly.

perhaps your app didnt crash? might be something else. you look at
dmesg ? and the xorg log?

mattOn Wed, 5 Sep 2007 00:20:15 +0800 cocobear <cocobear.cn at gmail.com> wrote:

Torsten Giebl wrote:

Use #include “SDL.h” and use it after stdio.h and stdlib.h

Why (in that order)?

Usually you would order the #includes from high level to low level, from
local/project headers to system headers. If your file is called X.c,
then your first #include should be X.h. This helps catch header
dependency errors.

SDL.h is at a higher level than stdio.h and stdlib.h (i.e. SDL can use
stdio and stdlib, but the C system headers cannot use SDL), so it should
go above stdio.h and stdlib.h. Right?–
Rainer Deyke - rainerd at eldwood.com

El Martes 04 Septiembre 2007 23:02, matt escribi?:

After I type ulimit -c unlimited ,I run the program,I didn’t got a
file named ‘core’.
Sorry for my poor english , maybe I am not understand you correctly.

perhaps your app didnt crash? ?might be something else. ?you look at
dmesg ? ?and the xorg log?

I think you have followed the instructions correctly. I also think that Matt
is right, it seems that your program is not crashing, it only manages to kill
the X server when querying for a valid video mode, hence you do not get a
stack dump.

2007/9/5, matt :> On Wed, 5 Sep 2007 00:20:15 +0800 cocobear <@cocobear> wrote:

After I type ulimit -c unlimited ,I run the program,I didn’t got a
file named ‘core’.
Sorry for my poor english , maybe I am not understand you correctly.

perhaps your app didnt crash? might be something else. you look at
dmesg ? and the xorg log?

matt


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I am sorry ,I am out this days,I can’t test on my own computer.