Memory access violation at IMG_Load()

Hello to all,

I’m using SDL and Image V1.2.4 library with MS Visual Studio 6 and I’m having
problems with loading PNG 32 images. My loading function looks like this:

{
img=IMG_Load(filename);
if (img)
{
SDL_SetAlpha(img, SDL_SRCALPHA , 255);
SDL_Surface* tmp_img=SDL_DisplayFormatAlpha (img);
if (tmp_img)
{
SDL_FreeSurface(img);
img=tmp_img;
}
}
}

I load many pictures but at some specific my code crushes at IMG_Load() call.
I get memory access violation error.
filename is correct. That specific image is also Ok. Everytime I run my code it
crushes at same place with same image. But when I reorganize code (I change
order of some row, which causes order change of images loading) it stop crushing
or start crushin at some other picture, but again always at same place. What can
cause IMG_Load() crush? Is there some debug technique that can help me find this
bug?

Any hint is welcome.–
Best regards,
Milan mailto:@Milan_Golubovic

I seem to remember there being a problem with the IMG_Load function on
Windows. It’s something about the operating system not allowing you to open
FILE pointers inside DLLs… Try something like this:

SDL_RWops *ops;
FILE *f = fopen(filename, “rb”); // make sure to open in binary mode
if (!f) {
// error
}

ops = SDL_RWFromFP(f, 0);
img = IMG_LoadPNG_RW(ops);

It’s been a while, and I’m not at my Win32 computer to test this right now,
so I can’t guarantee it will work… but this is how I remember doing it
when I had the same problem as you.

Good luck!On 3/9/07, Milan Golubovic wrote:

Hello to all,

I’m using SDL and Image V1.2.4 library with MS Visual Studio 6 and I’m
having
problems with loading PNG 32 images. My loading function looks like this:

{
img=IMG_Load(filename);
if (img)
{
SDL_SetAlpha(img, SDL_SRCALPHA , 255);
SDL_Surface* tmp_img=SDL_DisplayFormatAlpha (img);
if (tmp_img)
{
SDL_FreeSurface(img);
img=tmp_img;
}
}
}

I load many pictures but at some specific my code crushes at IMG_Load()
call.
I get memory access violation error.
filename is correct. That specific image is also Ok. Everytime I run my
code it
crushes at same place with same image. But when I reorganize code (I
change
order of some row, which causes order change of images loading) it stop
crushing
or start crushin at some other picture, but again always at same place.
What can
cause IMG_Load() crush? Is there some debug technique that can help me
find this
bug?

Any hint is welcome.


Best regards,
Milan mailto:golubovicm at gmail.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


“If you see somebody who you don’t know getting into a crop duster that
doesn’t belong to you, report them.” – President George W. Bush

I’ve used IMG_Load from a dll in win32 and it seems to be working fine…On 3/10/07, James Buchwald wrote:

I seem to remember there being a problem with the IMG_Load function on
Windows. It’s something about the operating system not allowing you to open
FILE pointers inside DLLs…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

IIRC the problem with Win32 DLLs and FILEs is that using a FILE opened in
a different module (EXE or DLL) will give you an access violation.

HTH,

Pete

“Brian” <brian.ripoff at gmail.com> wrote in message
news:…> I’ve used IMG_Load from a dll in win32 and it seems to be working fine…

On 3/10/07, James Buchwald wrote:

I seem to remember there being a problem with the IMG_Load function on
Windows. It’s something about the operating system not allowing you to
open
FILE pointers inside DLLs…


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org