SDL_Rect in SDL_ttf

i try to use sdl_ttf in a 2d context .
all works correctly but i ave a doubt about this piece of code :

SDL_Surface *screen=NULL;//the main surface
SDL_Surface *text=NULL;//surface to draw text

SDL_Rect dest2;//a test Rect

dest2.x = 50;
dest2.y = 50;
dest2.w = 0;//i have also tried negative values
dest2.h = 0;//i have also tried negative values

screen = SDL_SetVideoMode(1024,768,32,SDL_HWSURFACE);//for example

text=TTF_RenderText_Solid(myfont,“an example”, color)

SDL_FillRect(screen, NULL, mycolor);
SDL_BlitSurface(text, NULL, screen,&dest2);
SDL_UpdateRects(screen, 1,&dest);

in this case my function draw a simple text message, starting of course
at x=50 and y=50,but i dont understand why, because heght and width of
dest2 are for example zero or negative numbers, i think it was supposed
at least to have a SDL_parachute but i have no errors .

thanks in advance.

Alberto Glarey

Width and height of the /destination/ are ignored in an SDL_BlitSurface()
call. Those of the source are paid attention to, assuming it’s not a NULL
pointer (in which case, it’s assumed you want the entire source to be
copied).

Hope that makes sense!

-bill!
bill at newbreedsoftware.com "Hey Shatner, ya remember that episode of
http://newbreedsoftware.com/bill/ Space Trek where your show got cancelled?"On Tue, Feb 24, 2004 at 03:43:13PM +0100, Alberto Glarey wrote:

in this case my function draw a simple text message, starting of course
at x=50 and y=50,but i dont understand why, because heght and width of
dest2 are for example zero or negative numbers, i think it was supposed
at least to have a SDL_parachute but i have no errors .

please reply directly to me

Alberto Glarey (2004-02-24 15:43):

SDL_Surface *screen=NULL;//the main surface
SDL_Surface *text=NULL;//surface to draw text
why should i set screen to NULL? (i know its no sdl question :confused: )–
best regards

ionas

Hey Jonas,

It’s just good practice to initialize pointers to NULL that way you can
check if they are null, they havent been used yet.

if you dont initialize them to null, the could be any random value which
could be interpreted as a memory address and can cause long painful hours of
debugging memory corruption bugs/crashes.

For instance lets say you dont initialize the screen surface pointer to null
and whenever you run your program it crashes and you cant figure out why.
After a couple days you realize its because you never initialize the screen
or you assign with an == instead of an =. If you had initialized it to
null, you might have seen that the screen pointer was null sooner and been
like “ohhhh!”.

Also if you try to write to a pointer that is NULL, it will crash all the
time, but if you leave it at it’s random value and try to write to it,
theres a chance it will just write to wherever the pointer is pointing,
causing memory corruption in a random spot in memory, making your art have
wierd colored pixels in it that dont belong and stuff like that.

does that make sense? hope it helps!
Alan> ----- Original Message -----

From: jonashartmann@gmx.de (Jonas Hartmann)
To:
Sent: Thursday, February 26, 2004 4:26 AM
Subject: OT Question (Re: [SDL] SDL_Rect in SDL_ttf)

please reply directly to me

Alberto Glarey (2004-02-24 15:43):

SDL_Surface *screen=NULL;//the main surface
SDL_Surface *text=NULL;//surface to draw text
why should i set screen to NULL? (i know its no sdl question :confused: )


best regards

ionas

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

thank you! :slight_smile:
yes it helped me.

Alan Wolfe (2004-02-26 20:16):> Hey Jonas,

It’s just good practice to initialize pointers to NULL that way you can
check if they are null, they havent been used yet.

if you dont initialize them to null, the could be any random value which
could be interpreted as a memory address and can cause long painful hours of
debugging memory corruption bugs/crashes.

For instance lets say you dont initialize the screen surface pointer to null
and whenever you run your program it crashes and you cant figure out why.
After a couple days you realize its because you never initialize the screen
or you assign with an == instead of an =. If you had initialized it to
null, you might have seen that the screen pointer was null sooner and been
like “ohhhh!”.

Also if you try to write to a pointer that is NULL, it will crash all the
time, but if you leave it at it’s random value and try to write to it,
theres a chance it will just write to wherever the pointer is pointing,
causing memory corruption in a random spot in memory, making your art have
wierd colored pixels in it that dont belong and stuff like that.

does that make sense? hope it helps!


best regards

ionas