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:
15
fs.c
15
fs.c
@@ -61,6 +61,19 @@ static void* autosave_thread_func(void *arg) {
|
||||
AppState 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
|
||||
char filename[512];
|
||||
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);
|
||||
|
||||
// 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];
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user