Too much debug output

I’m a SDL-beginner and a C-beginner and I’m toying around with the
show-BMP-tutorials on the sdl-webpages.

Why do I get LOTS of such “debug” output like:

09895: symbol=SDL_UpperBlit; lookup in file=./test
09895: symbol=SDL_UpperBlit; lookup in file=/usr/lib/libSDL-1.2.so.0
09895: symbol=SDL_LowerBlit; lookup in file=./test
09895: symbol=SDL_LowerBlit; lookup in file=/usr/lib/libSDL-1.2.so.0
09895: symbol=SDL_MapSurface; lookup in file=./test
09895: symbol=SDL_MapSurface; lookup in file=/usr/lib/libSDL-1.2.so.0

from this code:

void show_bmp(char *file, SDL_Surface *scr, int x, int y)
{
SDL_Surface *pic;
SDL_Rect *area;

pic = SDL_LoadBMP(file);

area->x = x;
area->y = y;
area->h = x;
area->w = y;

SDL_BlitSurface(pic, NULL, scr, NULL);
SDL_UpdateRect(scr, 0, 0, pic->w, pic->h);
SDL_FreeSurface(pic);
}

and why does the output disappear as soon as I delete the
"area->…" lines?!

Greetings,–
klaus peter thorn
thorn at merlinux.de
postmaster at merlinux.de postmaster at uni-hildesheim.de
www.merlinux.de/thorn

I’m a SDL-beginner and a C-beginner and I’m toying around with the
show-BMP-tutorials on the sdl-webpages.

Why do I get LOTS of such “debug” output like:
[snip]
from this code:

void show_bmp(char *file, SDL_Surface *scr, int x, int y)
{
SDL_Surface *pic;
SDL_Rect *area;

The above line alloates memory for a pointer to an SDL_Rect structure. It
doesn’t allocate memory for the structure itself; only enough memory to hold
the address of a location in memory.

Change this to just:
SDL_Rect area;

which allocates memory for an SDL_Rect struct.

pic = SDL_LoadBMP(file);

area->x = x;
area->y = y;
area->h = x;
area->w = y;

These all tell the compiler to go to the address in memory that’s pointed to
by area (which is uninitialised; it may be NULL, or any other random value)
and set a value there. In other words; you’re trampling over some random
part of the system’s memory space. This makes programs crash, or when run
under a debugger, produce lots of output :slight_smile:

Change these to
area.x = x;
etc. The ‘.’ tells the compiler that area is an SDL_Rect, while ‘->’ tells
it that it’s a pointer to an SDL_Rect.

SDL_BlitSurface(pic, NULL, scr, NULL);
SDL_UpdateRect(scr, 0, 0, pic->w, pic->h);
SDL_FreeSurface(pic);
}

and why does the output disappear as soon as I delete the
"area->…" lines?!

As explained above :slight_smile:

However, you aren’t actually using this rectangle at all in the above code,
so you could delete all of it and it would work fine.

If any of the above didn’t make sense, you’d be well advised to pick up a
good book on the C programming language.On Fri, 7 Dec 2001, Klaus Thorn wrote:


Mike.