SDL_RWops ownership

Hi All,

SDL_mixer seems to load OGG music by piece by piece while it’s playing
(streaming) because my program segfaults when I free the SDL_RWops I passed
to Mix_LoadMUS_RW as soon as it returns.

If I load a MOD music, it seems that the entire music is loaded in memory
because I don’t get segfaults if I free the SDL_RWops.

Could someone clarify this? Can I just forget about SDL_RWops passed to
Mix_LoadMUS_RW because they will be closed and freed when the mixer is done
with them? Or I must always free them myself? Or I must free it if it’s a
MOD music and forget about it if it’s an OGG music?

Thanks,

Andre________________________________________________________________
Mensagem enviada pelo Microlink Webmail 12.7.8p3

Ok, I’ve put some printf’s and discovered how it works for MOD and OGG (I
think):

MOD: The music is entirely read to memory synchronously and SDL_mixer never
frees the SDL_RWops.
OGG: The music is loaded asynchronously in chunks as needed by SDL_mixer and
it never frees the SDL_RWops, not even when the music ends.

So the question is: how do you guys free SDL_RWops used to load music? For
MOD it could be right after Mix_LoadMUS_RW, but for OGG it can be only after
the music is stopped…

Someone contacted me privately and told me to save the pointer to SDL_RWops
in a global and check it before playing a music. If it’s different from
NULL, close and free it before playing the new music. But I thought about it
a little longer and it will break if I stop a music, play another one and
try to play the first one again. The SDL_RWops is gone and I’ll probably get
a segfault for OGG musics.

For now I’m thinking about making a structure with a Mix_Music* and a
SDL_RWops* and wrapping Mix_* function calls to deal with SDL_RWops as
needed – basically saving the both pointers when the music is loaded and
closing and freeing the pointer to SDL_RWops when the music is freed. All
other uses (play, fade in, fade out…) just keep SDL_RWops untouched.

If I’m completely lost here please someone enlighten me…

Thanks,

Andre

Hi All,

SDL_mixer seems to load OGG music by piece by piece while it’s playing
(streaming) because my program segfaults when I free the SDL_RWops I
passed
to Mix_LoadMUS_RW as soon as it returns.

If I load a MOD music, it seems that the entire music is loaded in memory
because I don’t get segfaults if I free the SDL_RWops.

Could someone clarify this? Can I just forget about SDL_RWops passed to
Mix_LoadMUS_RW because they will be closed and freed when the mixer is
done> with them? Or I must always free them myself? Or I must free it if it’s a
MOD music and forget about it if it’s an OGG music?

Thanks,

Andre


Mensagem enviada pelo Microlink Webmail 12.7.8p3

Ok, SDL_mixer takes the ownership of SDL_RWops passed to Mix_LoadMUS_RW.
They’re closed when you call Mix_FreeMusic.

This means you can pretty much forget the rwops you use to load musics. And
that I’ve enlighten myself.

Sorry for the noise.

Andre________________________________________________________________
Mensagem enviada pelo Microlink Webmail 12.7.8p3