Skip to content

Commit 842bef8

Browse files
committed
sound: FIX: do not free builtin sounds
1 parent 5ecdd86 commit 842bef8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/sound.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct sfxEffect {
3232
const char *name;
3333
void *buffer;
3434
int size;
35+
int builtin;
3536
};
3637

3738
static struct sfxEffect sfx_files[SFX_COUNT] = {
@@ -85,6 +86,7 @@ static int sfxRead(const char *full_path, struct sfxEffect *sfx)
8586

8687
sfx->buffer = buffer;
8788
sfx->size = size;
89+
sfx->builtin = 0;
8890

8991
return 0;
9092
}
@@ -93,16 +95,22 @@ static void sfxInitDefaults(void)
9395
{
9496
sfx_files[SFX_BOOT].buffer = boot_adp;
9597
sfx_files[SFX_BOOT].size = size_boot_adp;
98+
sfx_files[SFX_BOOT].builtin = 1;
9699
sfx_files[SFX_CANCEL].buffer = cancel_adp;
97100
sfx_files[SFX_CANCEL].size = size_cancel_adp;
101+
sfx_files[SFX_CANCEL].builtin = 1;
98102
sfx_files[SFX_CONFIRM].buffer = confirm_adp;
99103
sfx_files[SFX_CONFIRM].size = size_confirm_adp;
104+
sfx_files[SFX_CONFIRM].builtin = 1;
100105
sfx_files[SFX_CURSOR].buffer = cursor_adp;
101106
sfx_files[SFX_CURSOR].size = size_cursor_adp;
107+
sfx_files[SFX_CURSOR].builtin = 1;
102108
sfx_files[SFX_MESSAGE].buffer = message_adp;
103109
sfx_files[SFX_MESSAGE].size = size_message_adp;
110+
sfx_files[SFX_MESSAGE].builtin = 1;
104111
sfx_files[SFX_TRANSITION].buffer = transition_adp;
105112
sfx_files[SFX_TRANSITION].size = size_transition_adp;
113+
sfx_files[SFX_TRANSITION].builtin = 1;
106114
}
107115

108116
//Returns 0 (AUDSRV_ERR_NOERROR) if the sound was loaded successfully.
@@ -111,8 +119,10 @@ static int sfxLoad(struct sfxEffect *sfxData, audsrv_adpcm_t *sfx)
111119
int ret;
112120

113121
ret = audsrv_load_adpcm(sfx, sfxData->buffer, sfxData->size);
114-
free(sfxData->buffer);
115-
sfxData->buffer = NULL; //Mark the buffer as freed.
122+
if (sfxData->builtin == 0) {
123+
free(sfxData->buffer);
124+
sfxData->buffer = NULL; //Mark the buffer as freed.
125+
}
116126

117127
return ret;
118128
}

0 commit comments

Comments
 (0)