fix: add null checks for clip buffer before saving WAV files

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-04 10:33:24 +00:00
parent 5d2acbe1fb
commit 99bd840fbe

15
fs.c
View File

@@ -61,6 +61,19 @@ static void* autosave_thread_func(void *arg) {
AppState state; AppState state;
dispatcher_get_state(&state); dispatcher_get_state(&state);
// Only autosave if at least one clip has a valid buffer
bool has_valid_clip = false;
for (int i = 0; i < MAX_CLIPS; i++) {
if (state.clips[i].buffer != NULL && state.clips[i].buffer_size > 0) {
has_valid_clip = true;
break;
}
}
if (!has_valid_clip) {
pthread_mutex_unlock(&autosave_mutex);
continue;
}
// Generate autosave filename with timestamp // Generate autosave filename with timestamp
char filename[512]; char filename[512];
time_t t = time(NULL); time_t t = time(NULL);
@@ -191,7 +204,7 @@ int fs_save_project(const char *filename, AppState *state) {
write_uint32(f, "read_position", clip->read_position); write_uint32(f, "read_position", clip->read_position);
// Save sample buffer to separate .wav file // Save sample buffer to separate .wav file
if (clip->buffer && clip->buffer_size > 0) { if (clip->buffer != NULL && clip->buffer_size > 0) {
char wav_path[1024]; char wav_path[1024];
snprintf(wav_path, sizeof(wav_path), "%s/clip_%d.wav", samples_dir, i); snprintf(wav_path, sizeof(wav_path), "%s/clip_%d.wav", samples_dir, i);
save_wav_float(wav_path, clip->buffer, clip->buffer_size, state->sample_rate); save_wav_float(wav_path, clip->buffer, clip->buffer_size, state->sample_rate);