SDL_DisplayFormat before SDL_VideoInit

Hi, I’m new to SDL and I would make a question.

If I call the function

SDL_Surface *surface = SDL_DisplayFormat (image)
if (surface == NULL)
exit()
?
?
SDL_VideoInit(?)

I get a crash in the first call.

Yes, I know that the SDL_DisplayFormat have to be called after the SDL_VideoInit
but I think that the user, at least, expect to have a NULL surface otherwise.
So I got a look athttp://gmane.org/word.php?id=29554
http://gmane.org/word.php?id=29554 the source code and I saw that
SDL_DisplayFormat check the
SDL_PublicSurface variable before doing anything.
But if the video isn?t initialized then this variable is not initialized too, am
I right?
Isn’t it better to test the current_video variable instead?
What do you think?

Thanks for the great library.

Best regards, Dahman

Hello !

SDL_Surface *surface = SDL_DisplayFormat (image)
if (surface == NULL) exit() ??? ??? SDL_VideoInit(???)

What should these two lines of code do ?

If you want to have your surface pointer set to
NULL from the start do this :

SDL_Surface *surface = NULL;

After this you can then call SDL_Init (SDL_INIT_VIDEO)
then use SDL_SetVideoMode and so on.

For a better understanding what you need to do,
look at the examples that come with SDL, like the testsprite.

CU

I think it’s correct to crash because what you suggest is an incorrect use
of the library also known as a programmer error. SDL_DisplayFormat only make
sens once you have a display context.–
Olivier Delannoy
ATER
PRiSM Laboratory
Versailles University, FRANCE

Yes, I know that the SDL_DisplayFormat have to be called after the SDL_VideoInit
but I think that the user, at least, expect to have a NULL surface otherwise.

SDL doesn’t spend time checking if the library is properly initialized
in every function…it assumes you did this part right, and calls your
attention to it by crashing when you don’t. :slight_smile:

We do basic sanity checks when they make sense, and where there are
legitimate places where such an error could occur…not calling
SDL_Init() first isn’t one of them, since it’s a fundamental, easy to
fix application issue.

–ryan.