When opening music file via filehandle, made sure buffer is freed after playing to prevent major memory leakage
This commit is contained in:
parent
5e3be36c39
commit
328ddd8a55
|
@ -5,6 +5,7 @@ D1X-Rebirth Changelog
|
||||||
arch/sdl/digi_mixer.c, arch/sdl/digi_mixer_music.c, arch/sdl/jukebox.c, d1x-rebirth.xcodeproj/project.pbxproj, main/multi.h: On Mac OS X - no longer have to copy SDL_mixer.h to SDL framework; frameworks can now be in /Library/Frameworks; fix for obscure compile error involving u_int32_t
|
arch/sdl/digi_mixer.c, arch/sdl/digi_mixer_music.c, arch/sdl/jukebox.c, d1x-rebirth.xcodeproj/project.pbxproj, main/multi.h: On Mac OS X - no longer have to copy SDL_mixer.h to SDL framework; frameworks can now be in /Library/Frameworks; fix for obscure compile error involving u_int32_t
|
||||||
include/ogl_init.h, 2d/font.c, arch/ogl/ogl.c, arch/ogl/gr.c: Rewrote code to control Texture Filtering a little so it's easier to apply Mipmaps for different parts of the game independently
|
include/ogl_init.h, 2d/font.c, arch/ogl/ogl.c, arch/ogl/gr.c: Rewrote code to control Texture Filtering a little so it's easier to apply Mipmaps for different parts of the game independently
|
||||||
main/gamecntl.c, main/menu.c, main/newdemo.c, main/newdemo.h: Using PHYSFSX_findFiles to make sure random demo playback will only find actual demo files and not quit autodemo; added DEMO_EXT for an universal definition of demo file extension
|
main/gamecntl.c, main/menu.c, main/newdemo.c, main/newdemo.h: Using PHYSFSX_findFiles to make sure random demo playback will only find actual demo files and not quit autodemo; added DEMO_EXT for an universal definition of demo file extension
|
||||||
|
arch/sdl/digi_mixer_music.c: When opening music file via filehandle, made sure buffer is freed after playing to prevent major memory leakage
|
||||||
|
|
||||||
20100901
|
20100901
|
||||||
--------
|
--------
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
|
|
||||||
Mix_Music *current_music = NULL;
|
Mix_Music *current_music = NULL;
|
||||||
|
char *current_music_hndlbuf = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Plays a music file from an absolute path or a relative path
|
* Plays a music file from an absolute path or a relative path
|
||||||
|
@ -33,7 +34,7 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)())
|
||||||
SDL_RWops *rw = NULL;
|
SDL_RWops *rw = NULL;
|
||||||
PHYSFS_file *filehandle = NULL;
|
PHYSFS_file *filehandle = NULL;
|
||||||
char midi_filename[PATH_MAX], full_path[PATH_MAX];
|
char midi_filename[PATH_MAX], full_path[PATH_MAX];
|
||||||
char *basedir = "music", *fptr, *buf = NULL;
|
char *basedir = "music", *fptr;
|
||||||
int bufsize = 0;
|
int bufsize = 0;
|
||||||
|
|
||||||
mix_free_music(); // stop and free what we're already playing, if anything
|
mix_free_music(); // stop and free what we're already playing, if anything
|
||||||
|
@ -72,9 +73,9 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)())
|
||||||
filehandle = PHYSFS_openRead(filename);
|
filehandle = PHYSFS_openRead(filename);
|
||||||
if (filehandle != NULL)
|
if (filehandle != NULL)
|
||||||
{
|
{
|
||||||
buf = realloc(buf, sizeof(char *)*PHYSFS_fileLength(filehandle));
|
current_music_hndlbuf = d_realloc(current_music_hndlbuf, sizeof(char *)*PHYSFS_fileLength(filehandle));
|
||||||
bufsize = PHYSFS_read(filehandle, buf, sizeof(char), PHYSFS_fileLength(filehandle));
|
bufsize = PHYSFS_read(filehandle, current_music_hndlbuf, sizeof(char), PHYSFS_fileLength(filehandle));
|
||||||
rw = SDL_RWFromConstMem(buf,bufsize*sizeof(char));
|
rw = SDL_RWFromConstMem(current_music_hndlbuf,bufsize*sizeof(char));
|
||||||
PHYSFS_close(filehandle);
|
PHYSFS_close(filehandle);
|
||||||
current_music = Mix_LoadMUS_RW(rw);
|
current_music = Mix_LoadMUS_RW(rw);
|
||||||
}
|
}
|
||||||
|
@ -89,6 +90,11 @@ int mix_play_file(char *filename, int loop, void (*hook_finished_track)())
|
||||||
{
|
{
|
||||||
con_printf(CON_CRITICAL,"Music %s could not be loaded\n", filename);
|
con_printf(CON_CRITICAL,"Music %s could not be loaded\n", filename);
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
|
if (current_music_hndlbuf)
|
||||||
|
{
|
||||||
|
d_free(current_music_hndlbuf);
|
||||||
|
current_music_hndlbuf = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -103,6 +109,11 @@ void mix_free_music()
|
||||||
Mix_FreeMusic(current_music);
|
Mix_FreeMusic(current_music);
|
||||||
current_music = NULL;
|
current_music = NULL;
|
||||||
}
|
}
|
||||||
|
if (current_music_hndlbuf)
|
||||||
|
{
|
||||||
|
d_free(current_music_hndlbuf);
|
||||||
|
current_music_hndlbuf = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mix_set_music_volume(int vol)
|
void mix_set_music_volume(int vol)
|
||||||
|
@ -114,6 +125,11 @@ void mix_set_music_volume(int vol)
|
||||||
void mix_stop_music()
|
void mix_stop_music()
|
||||||
{
|
{
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
|
if (current_music_hndlbuf)
|
||||||
|
{
|
||||||
|
d_free(current_music_hndlbuf);
|
||||||
|
current_music_hndlbuf = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mix_pause_music()
|
void mix_pause_music()
|
||||||
|
|
Loading…
Reference in a new issue