SDL_RWops

I’ve finally managed to read my graphics and sound out of a package file,
into memory and use them directly from there (if that makes sense). Whilst
it works, there is a small concern…

I have a function that I pass a filename to and it looking in the pak file
for the data and read it. It does so like this,
(I’ve condensed it slightly, so you get the idea)

unsigned char *packBuffer;

int packFSize = fread(&packFSize, sizeof(int), 1, pak);

packBuffer = (unsigned char*) malloc(packFSize);

sdlrw = SDL_RWFromMem(packBuffer, packFSize);

where sdlrw is a global SDL_RWops object.

This is all fine, but at the end of the function I do not free the allocated
packBuffer memory. Instead I read the image data like this,

SDL_Surface *image = IMG_Load_RW(sdlrw, 1);

What happens to the memory I allocated in to packBuffer in the earlier
function? If I free it before leaving the function then I get an error that
there is no image data (or the image is unsupported).

Am I right in thinking that since I have asked for the source to be freed
(by specify 1 in IMG_Load_RW) that my packBuffer data is being freed?

Thanks

Steve :slight_smile:

“Sweeney, Steven (FNB)” writes:

I’ve finally managed to read my graphics and sound out of a package file,
into memory and use them directly from there (if that makes sense). Whilst
it works, there is a small concern…

I have a function that I pass a filename to and it looking in the pak file
for the data and read it. It does so like this,
(I’ve condensed it slightly, so you get the idea)

unsigned char *packBuffer;

int packFSize = fread(&packFSize, sizeof(int), 1, pak);

packBuffer = (unsigned char*) malloc(packFSize);

sdlrw = SDL_RWFromMem(packBuffer, packFSize);

where sdlrw is a global SDL_RWops object.

This is all fine, but at the end of the function I do not free the allocated
packBuffer memory. Instead I read the image data like this,

SDL_Surface *image = IMG_Load_RW(sdlrw, 1);
AFAIK, this closes sdlrw (SDL_RWops object) but leaves you malloced buffer intact.
You have to free you packBuffer yourself.

Am I right in thinking that since I have asked for the source to be freed
(by specify 1 in IMG_Load_RW) that my packBuffer data is being freed?
No, you just asked to close SDL_RWops object. It doesn’t free memory
from which it was created.

– Ed

SDL_RWops tutorial with zlib doesn’t work (i’ve just triad it with
IMG_LoadBMP_RW)
does anyone know where i can find a good documentation about SDL_RWops?------------------------------------------------------------------
Virus taramasi Vexira AV programi kullanilarak Is Net tarafindan yapilmistir.
This e-mail is checked by Is Net against all known types of viruses using Vexira AV.
Is Net’in en ucuz saatlik kullanim paketi Teneffus.Net’i ve en ucuz sinirsiz erisim paketi Taksitli Ekonet’i duymus muydunuz?
http://www.isnet.net.tr/teneffusnet/
http://www.isnet.net.tr/taksitliekonet/

The tutorial worked for me, and I was using successfully zziplib at the end.

When using the zlib (or zzlib) library as Windows-DLL under SDL
#define ZLIB_DLL (or #define ZZLIB_DLL) has to be added before
including zlib.h (or zzlib.h). Otherwise you will get link errors.

Maybe get the zziplib, there should also be some notes
for getting it (and zlib) working with SDL.> ----- Original Message -----

From: cbas@isbank.net.tr (COSKU BAS)
To:
Sent: Thursday, April 10, 2003 3:44 AM
Subject: [SDL] SDL_RWops

SDL_RWops tutorial with zlib doesn’t work (i’ve just triad it with
IMG_LoadBMP_RW)
does anyone know where i can find a good documentation about SDL_RWops?


Virus taramasi Vexira AV programi kullanilarak Is Net tarafindan yapilmistir.
This e-mail is checked by Is Net against all known types of viruses using Vexira AV.
Is Net’in en ucuz saatlik kullanim paketi Teneffus.Net’i ve en ucuz sinirsiz erisim paketi Taksitli Ekonet’i duymus muydunuz?
http://www.isnet.net.tr/teneffusnet/
http://www.isnet.net.tr/taksitliekonet/