Skip to content

Commit fdb3d52

Browse files
committed
fix #143
1 parent 3accc6e commit fdb3d52

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

arm9/source/tobkit/recordbox.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ RecordBox::RecordBox(u16 **_vram, void (*_onOk)(void), void (*_onCancel)(void),
4141
:Widget((SCREEN_WIDTH-RECORDBOX_WIDTH)/2, (SCREEN_HEIGHT-RECORDBOX_HEIGHT)/2,
4242
RECORDBOX_WIDTH, RECORDBOX_HEIGHT, _vram, true),
4343
recording(false), btndown(false), onOk(_onOk), onCancel(_onCancel), sample(_sample),
44-
instrument(_instrument), smpidx(_smpidx), sound_data(0)
44+
instrument(_instrument), smpidx(_smpidx), sound_data(NULL)
4545
{
4646
title = "sample recorder";
4747

@@ -68,6 +68,9 @@ RecordBox::RecordBox(u16 **_vram, void (*_onOk)(void), void (*_onCancel)(void),
6868

6969
RecordBox::~RecordBox(void)
7070
{
71+
if(sound_data)
72+
free(sound_data);
73+
7174
delete labelmsg;
7275
delete labelmsg2;
7376
delete labelrec;
@@ -185,9 +188,11 @@ void RecordBox::startRecording(void)
185188
if(sample != NULL)
186189
instrument->setSample(smpidx, NULL); // Deletes the sample
187190

188-
if(sound_data) free(sound_data);
191+
if(sound_data)
192+
free(sound_data);
189193
sound_data = (u16*)malloc(RECORDBOX_SOUNDDATA_SIZE);
190-
if(!sound_data) return;
194+
if(!sound_data)
195+
return;
191196

192197
// Start recording
193198
DC_FlushAll();
@@ -208,10 +213,11 @@ void RecordBox::stopRecording()
208213
// Security check
209214
if(size < RECORDBOX_CROP_SAMPLES_END + RECORDBOX_CROP_SAMPLES_START)
210215
{
211-
free(sound_data);
216+
if(sound_data)
217+
free(sound_data);
212218
sound_data = NULL;
213219
sample = NULL;
214-
onOk();
220+
onCancel();
215221
debugprintf("recorded data too small\n");
216222
return;
217223
}

0 commit comments

Comments
 (0)