Prob w/SDL_RWFromFile&SDL_ReadBE16

hiya,

…this is driving me nuts…I’m basing my PSD loading code on the
SDL_bmp.c code where the following is done:

/* Read in the BMP file header */
fp_offset = SDL_RWtell(src);
SDL_ClearError();
if ( SDL_RWread(src, magic, 1, 2) != 2 ) {
	SDL_Error(SDL_EFREAD);
	was_error = 1;
	goto done;
}
if ( strncmp(magic, "BM", 2) != 0 ) {
	SDL_SetError("File is not a Windows BMP file");
	was_error = 1;
	goto done;
}
bfSize		= SDL_ReadLE32(src);=============================================

my code snippet is the following in cpp (on OSX):

 SDL_RWops *src;
 src = SDL_RWFromFile( FileName, "rb");
 fp_offset = SDL_RWtell(src);
 SDL_ClearError();
 if ( SDL_RWread(src, magic, 1, 4) != 4 )
 {
         //SDL_Error(SDL_EFREAD);
         SDL_RWclose(src);
         return NULL;
 }
 if ( (magic[0] == 'B') && (magic[1] == 'M') )	//load BMP
 {
         //SDL_RWclose(src);
         return NULL;
 }
 if ( (magic[0] == '8') && (magic[1] == 'B') )	//load PSD
 {
     PSDFile *Psd;
     Psd->Version = SDL_ReadBE16(src);

=====================================================

…the problem is that everytime I get to SDL_ReadBE16(src), I get an
EXC_BAD_ACCESS! Am I overlooking something?

thanks,
jamie
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 2386 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030506/f4e468d9/attachment.bin

Me wrote:

     PSDFile *Psd;
     Psd->Version = SDL_ReadBE16(src);

=====================================================

…the problem is that everytime I get to SDL_ReadBE16(src), I get an
EXC_BAD_ACCESS! Am I overlooking something?

Yes. Dereferencing Psd is undefined because there’s no memory allocated
on the end of that pointer.–
Kylotan
http://pages.eidosnet.co.uk/kylotan

Me wrote:

     PSDFile *Psd;
     Psd->Version = SDL_ReadBE16(src);

=====================================================

…the problem is that everytime I get to SDL_ReadBE16(src), I get an
EXC_BAD_ACCESS! Am I overlooking something?

Yes. Dereferencing Psd is undefined because there’s no memory allocated
on the end of that pointer.

hi kylotan,

…actually there is, I just didn’t include that in the snippet :wink:

…after a bit more brainstorming (and potentially showing my ignorance
of the, uh, “finer points” of c vs. c++), I found that I could get
around this if I made the “SDL_RWops *src” into a global variable…but
that screws up other variables that should be available…I’ll put this
aside until I can find a c++ reference book at home…

l8r,
jamieOn Tuesday, May 6, 2003, at 01:35 PM, Kylotan wrote: