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:
@@ -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
|
||||
|
||||
6
engine.c
6
engine.c
@@ -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] = {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user