Can't write a suitable SDL_RWops

hi I’m trying to write a suitable routine which played, using SDL, an mp3
track included in an avi file. (I can play wave tracks, but ,obviously, avi
files are encoded using maily mp3 [or vorbis]). Here is part of my code:

static int _mymem_seek(SDL_RWops *context, int offset, int whence)
return 0;

static int _mymem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
LGSdl *LL;
unsigned char *rwbuf = (unsigned char *) context->hidden.unknown.data1;
size_t nread = LL->read_buffer(rwbuf, size);
return nread /size;

static int _mymem_write(SDL_RWops *context, const void *ptr, int size, int
return 0;

static int _mymem_close(SDL_RWops context)
if ( context )
if ( context->hidden.unknown.data1 )
unsigned char
stream = (unsigned char*) context->hidden.unknown.data1;
delete stream;
return 0;

SDL_RWops *SDL_RWFromMemoria(void mem, int size)

unsigned char *rwbuffer;
rwbuffer = new unsigned char[BUFFSIZE];

rwops = SDL_AllocRW ();

if ( rwops != NULL )
	rwops->read 	= _mymem_read;
	rwops->write 	= _mymem_write;
	rwops->seek 	= _mymem_seek;
	rwops->close 	= _mymem_close;
	rwops->hidden.unknown.data1 = rwbuffer;

	return rwops;


I call the constructor once with

	rw = SDL_RWFromMemoria((void *)data, size);
	sample = Sound_NewSample(rw, "MP3", NULL, BUFFSIZE);

I fill the buffer with

	write_buffer(data, size);

the callback function is this:

void LGSdl::callback(void *stream, int len)
int maxnum;
SDL_RWread(rw, stream, len, maxnum);

The program crashes.


luigi wrote:

SDL_RWops *SDL_RWFromMemoria(void *mem, int size)

  1. Don’t ever name your own functions SDL_something.

  2. Use SDL_RWFromMem.–
    Rainer Deyke | root at |