forked from JailDoctor/JailAudio
Hopefully solved memory issues on deallocation
This commit is contained in:
@@ -78,7 +78,7 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
|||||||
|
|
||||||
JA_Music JA_LoadMusic(const char* filename) {
|
JA_Music JA_LoadMusic(const char* filename) {
|
||||||
int chan, samplerate;
|
int chan, samplerate;
|
||||||
JA_Music music = (JA_Music)SDL_malloc(sizeof(JA_Music_t));
|
JA_Music music = new JA_Music_t();
|
||||||
music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
||||||
|
|
||||||
SDL_AudioCVT cvt;
|
SDL_AudioCVT cvt;
|
||||||
@@ -130,8 +130,8 @@ JA_Music_state JA_GetMusicState() {
|
|||||||
|
|
||||||
void JA_DeleteMusic(JA_Music music) {
|
void JA_DeleteMusic(JA_Music music) {
|
||||||
if (current_music == music) current_music = NULL;
|
if (current_music == music) current_music = NULL;
|
||||||
free(music->output);
|
SDL_free(music->output);
|
||||||
free(music);
|
delete music;
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_Sound JA_LoadSound(const char* filename) {
|
JA_Sound JA_LoadSound(const char* filename) {
|
||||||
@@ -145,7 +145,7 @@ JA_Sound JA_LoadSound(const char* filename) {
|
|||||||
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
|
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
|
||||||
SDL_ConvertAudio(&cvt);
|
SDL_ConvertAudio(&cvt);
|
||||||
free(sound->buffer);
|
SDL_FreeWAV(sound->buffer);
|
||||||
sound->buffer = cvt.buf;
|
sound->buffer = cvt.buf;
|
||||||
sound->length = cvt.len_cvt;
|
sound->length = cvt.len_cvt;
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ void JA_DeleteSound(JA_Sound sound) {
|
|||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
||||||
if (channels[i].sound == sound) JA_StopChannel(i);
|
if (channels[i].sound == sound) JA_StopChannel(i);
|
||||||
}
|
}
|
||||||
SDL_FreeWAV(sound->buffer);
|
SDL_free(sound->buffer);
|
||||||
delete sound;
|
delete sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user