Skip to content

Commit e23e7d3

Browse files
committed
synthio: get_buffer: return error if object deinited
this may fix a weird crash during shutdown
1 parent 2b0231e commit e23e7d3

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

shared-module/synthio/MidiTrack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ void synthio_miditrack_reset_buffer(synthio_miditrack_obj_t *self,
158158

159159
audioio_get_buffer_result_t synthio_miditrack_get_buffer(synthio_miditrack_obj_t *self,
160160
bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) {
161+
if (common_hal_synthio_miditrack_deinited(self)) {
162+
*buffer_length = 0;
163+
return GET_BUFFER_ERROR;
164+
}
161165

162166
synthio_synth_synthesize(&self->synth, buffer, buffer_length, single_channel_output ? 0 : channel);
163167
if (self->synth.span.dur == 0) {

shared-module/synthio/Synthesizer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ void synthio_synthesizer_reset_buffer(synthio_synthesizer_obj_t *self,
6262

6363
audioio_get_buffer_result_t synthio_synthesizer_get_buffer(synthio_synthesizer_obj_t *self,
6464
bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) {
65+
if (common_hal_synthio_synthesizer_deinited(self)) {
66+
*buffer_length = 0;
67+
return GET_BUFFER_ERROR;
68+
}
6569
self->synth.span.dur = SYNTHIO_MAX_DUR;
6670
synthio_synth_synthesize(&self->synth, buffer, buffer_length, single_channel_output ? channel : 0);
6771
return GET_BUFFER_MORE_DATA;

0 commit comments

Comments
 (0)