Skip to content

Commit

Permalink
Fix startup without device
Browse files Browse the repository at this point in the history
Startup without device causes a segmentation fault (at least here).
Show an error if the device_init is not successfull.
  • Loading branch information
soyersoyer committed Jan 22, 2024
1 parent 6b8c9ba commit f94a4be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static gint query_program(const gint pgm_num)


#define DEV_NAME_MAX_LEN 64
void device_init(void)
int device_init(void)
{
guint dev_count;
#ifdef HAVE_RTMIDI4
Expand Down Expand Up @@ -153,7 +153,7 @@ void device_init(void)
if (!found) {
g_critical("No MPKmini MK3 device found");
rtmidi_in_free(midi_in);
return;
return -1;
}
g_debug("Using device %d: %s", i, dev_name);
midi_out = rtmidi_out_create_default();
Expand All @@ -167,6 +167,8 @@ void device_init(void)

dev.in = midi_in;
dev.out = midi_out;

return 0;
}


Expand Down
2 changes: 1 addition & 1 deletion src/device.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _DEVICE_H
#define _DEVICE_H

void device_init(void);
int device_init(void);
void device_close(void);
gint device_read_pgm(gint pgm_num);
gint device_write_pgm(gint pgm_num);
Expand Down
5 changes: 4 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ int main(int argc, char ** argv)
GtkWidget *app_win;

gtk_init(&argc, &argv);
device_init();
if (device_init() < 0) {
show_error();
return -1;
}
if (device_read_pgm(PGM_NUM_RAM) < 0) {
show_error();
return -1;
Expand Down

0 comments on commit f94a4be

Please sign in to comment.