fix: add NULL checks for clip buffer and MIDI events in process callback

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-03 20:49:24 +00:00
parent 13cbe0c303
commit b74db49d7f
2 changed files with 9 additions and 5 deletions

View File

@@ -533,7 +533,11 @@ AppState reducer(AppState state, Action action) {
mclip->event_count = 0;
mclip->read_index = 0;
mclip->max_events = MAX_MIDI_EVENTS;
// events pointer should already be valid from init
// Ensure events pointer is valid
if (mclip->events == NULL) {
mclip->events = (MidiEvent *)calloc(MAX_MIDI_EVENTS, sizeof(MidiEvent));
mclip->max_events = MAX_MIDI_EVENTS;
}
}
// Reset Carla host

View File

@@ -102,7 +102,7 @@ static int process_callback(jack_nframes_t nframes, void *arg) {
int clip_idx = g * GRID_ROWS * GRID_COLS + s * GRID_COLS + ch;
MidiClip *mclip = &state.midi_clips[clip_idx];
if (mclip->state == CLIP_LOOPING && mclip->event_count > 0) {
if (mclip->state == CLIP_LOOPING && mclip->event_count > 0 && mclip->events != NULL) {
if (mclip->read_index < mclip->event_count) {
int idx = mclip->read_index;
uint8_t msg[3] = {
@@ -113,7 +113,7 @@ static int process_callback(jack_nframes_t nframes, void *arg) {
jack_midi_event_write(midi_out_buf,
mclip->events[idx].timestamp, msg, 3);
mclip->read_index++;
if (mclip->read_index >= mclip->event_count) {
mclip->read_index = 0;
}
@@ -145,12 +145,12 @@ static int process_callback(jack_nframes_t nframes, void *arg) {
Clip *clip = &state.clips[clip_idx];
if (clip->state == CLIP_RECORDING) {
if (clip->write_position < MAX_BUFFER_SIZE) {
if (clip->write_position < MAX_BUFFER_SIZE && clip->buffer != NULL) {
clip->buffer[clip->write_position++] = audio_in[ch][i];
}
}
if (clip->state == CLIP_LOOPING && clip->buffer_size > 0) {
if (clip->state == CLIP_LOOPING && clip->buffer_size > 0 && clip->buffer != NULL) {
rack_in[i] += clip->buffer[clip->read_position];
clip->read_position = (clip->read_position + 1) % clip->buffer_size;
}