Hi
Whenever i use SDL_DisplayFormat in addition with IMG_load (from SDL_image
libary) i get an segmentation Fault:
SDL_Surface * blah = SDL_DisplayFormat ( IMG_Load ( “data/images/block0.jpg”))
I don’t know what i’m doing wrong here. IMG_Load returns a Pointer to a
SDL_Surface and SDL_DisplayFormat expects a pointer to a SDL_Surface.
Any suggestions ?
You can’t check to see if IMG_Load returns NULL if you do it like that, and
you can’t free the surface either.
Try doing it like this:
SDL_Surface * blah=NULL;
SDL_Surface * temp=IMG_Load ( “data/images/block0.jpg”);
if(temp){
blah=SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
}else{
//handle the error.
}> ----- Original Message -----
From: altaycebe@vpw.wh.uni-dortmund.de (Altay Cebe)
To:
Sent: Wednesday, October 30, 2002 4:40 PM
Subject: [SDL] Using IMG_Load with SDL_DisplayFormat
Hi
Whenever i use SDL_DisplayFormat in addition with IMG_load (from SDL_image
libary) i get an segmentation Fault:
SDL_Surface * blah = SDL_DisplayFormat ( IMG_Load (
“data/images/block0.jpg”))
I don’t know what i’m doing wrong here. IMG_Load returns a Pointer to a
SDL_Surface and SDL_DisplayFormat expects a pointer to a SDL_Surface.
Any suggestions ?
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
Ok, thank you for your help.
It works better (cleaner) now !
No, wait…it still doesn’t work the way i want :-((
This works:
SDL_Surface * temp=IMG_Load ( “data/images/block.jpg”);
if(temp){
blah=SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
}
else
{
//handle the error.
cout << "ERROR " << endl;
exit(1);
}
But I would like to store all SDL_Surfaces in a array
SDL_Surface ** pSurface_Array = new SDL_Surface[ objectCount ];
But when i try
pSurface_Array[i] = NULL;
SDL_Surface * temp= IMG_Load ( imageName );
SDL_Surface * blah = NULL;
if(temp){
blah=SDL_DisplayFormat(temp);
pSurface_Array[i]= blah;
SDL_FreeSurface(temp);
SDL_FreeSurface(blah);
}
else
{
//handle the error.
cout << "ERROR " << endl;
exit(1);
}
it still Segfaults. It doesn’t work for that pSurface_Array . I experimented a
bit, but i can’t keep it from seg faulting. It seems that temp is != NULL
because it doesn’t even print “ERROR”.
Altay Cebe wrote:
But I would like to store all SDL_Surfaces in a array
SDL_Surface ** pSurface_Array = new SDL_Surface[ objectCount ];
new SDL_Surface[ objectCount ] is asking for an array of SDL_Surfaces.
This isn’t what you want - you want an array of SDL_Surface pointers,
which you can then initialise with IMG_Load. I’d probably do it like
this for clarity
typedef SDL_Surface* ptrSDL_Surface;
ptrSDL_Surface* pSurface_Array = new ptrSDL_Surface[objectCount];
Feel free to remove the typedef, but it’s there to make it explicit that
you’re allocating an array of pointers.–
Kylotan
http://pages.eidosnet.co.uk/kylotan
Hi,
if(temp){
blah=SDL_DisplayFormat(temp);
pSurface_Array[i]= blah;
SDL_FreeSurface(temp);
SDL_FreeSurface(blah); <-- You don’t want to do this!
}
leaves pSurface_Array[i] pointing to a surface you just freed,
cheers,
John.> ----- Original Message -----
From: altaycebe@vpw.wh.uni-dortmund.de (Altay Cebe)
To:
Sent: Wednesday, October 30, 2002 11:26 PM
Subject: Re: [SDL] Using IMG_Load with SDL_DisplayFormat
No, wait…it still doesn’t work the way i want :-((
This works:
SDL_Surface * temp=IMG_Load ( “data/images/block.jpg”);
if(temp){
blah=SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
}
else
{
//handle the error.
cout << "ERROR " << endl;
exit(1);
}
But I would like to store all SDL_Surfaces in a array
SDL_Surface ** pSurface_Array = new SDL_Surface[ objectCount ];
But when i try
pSurface_Array[i] = NULL;
SDL_Surface * temp= IMG_Load ( imageName );
SDL_Surface * blah = NULL;
if(temp){
blah=SDL_DisplayFormat(temp);
pSurface_Array[i]= blah;
SDL_FreeSurface(temp);
SDL_FreeSurface(blah);
}
else
{
//handle the error.
cout << "ERROR " << endl;
exit(1);
}
it still Segfaults. It doesn’t work for that pSurface_Array . I experimented
a
bit, but i can’t keep it from seg faulting. It seems that temp is != NULL
because it doesn’t even print “ERROR”.
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
Ok, thanks erveryone for help !
It really works now.