Surface into a structur

Hi,
I made a struct like this:

struct obj
{
int x, y;
int dx, dy;
SDL_Surface *image;
}obj;

obj menu[4];

when I tried to use it:

menu[0]->image = IMG_Load(image);

I received an segmentation fault… anybody know why?
tnx

Since menu[0] is an “obj” and not an “obj *” I think you need to use
the . operator instead of ->

eg:
menu[0].image = IMG_Load(image);

Though I think the compiler should report that as an error. What are
you compiling with?

-MikeOn Fri, 03 Dec 2004 16:16:50 +0100, NighTiger wrote:

Hi,
I made a struct like this:

struct obj
{
int x, y;
int dx, dy;
SDL_Surface *image;
}obj;

obj menu[4];

when I tried to use it:

menu[0]->image = IMG_Load(image);

obj menu[4];
menu[0]->image = IMG_Load(image);

menu[0].image is what you want.

–ryan.

NighTiger wrote:

Hi,
I made a struct like this:
struct obj
{
int x, y;
int dx, dy;
SDL_Surface *image;
}obj;
obj menu[4];
when I tried to use it:
menu[0]->image = IMG_Load(image);
I received an segmentation fault… anybody know why?

assuming you have menu[0].image = IMG_Load(image);

perhaps it failed to load the image, and you are using a NULL pointer.
always check return values for errors…

-LIM-