so, im trying to load some audio and font files from a zip, right now im doing this:
Code:
if (PHYSFS_exists(file)){
PHYSFS_file *R_File = PHYSFS_openRead(file);
PHYSFS_sint64 Size = PHYSFS_fileLength(R_File);
char *Data = new char[(Uint32)PHYSFS_fileLength(R_File)];
PHYSFS_read(R_File, Data, 1, (PHYSFS_sint32)Size);
SDL_RWops *_RW = SDL_RWFromMem(Data, (int)Size);
PHYSFS_close(R_File);
}
and then i just use the _RW variable to make a open a font like this:
TTF_DroidSerif = TTF_OpenFontRW(_RW, 0, font_size);
my question would be regarding the char* Data, how should i procced to handle its memory so i can do a delete[] in a correct way. …?
if i delete the data after SDL_RWFromMem the rwops does not work anymore, same thing for sound files, im assuming is because fonts and audio files are not loaded as images, you may not use all the glyphs in a font, and you may not play every sound of an audio file. so the data is needed for as long as the struct itself.
both sdl_ttf and sdl_mixer ask me for the “freesrc” parameter in the creation functions, would that be sufficient to free the char* Data from before?. or do i need some kind of struct to keep all the data and then deleting according?
what are the best approaches that you guys have for this kind of stuff?