From 6a06b40251823c27aa444979829621baef1ad433 Mon Sep 17 00:00:00 2001 From: Adam Avramov Date: Wed, 13 May 2015 21:21:55 +0300 Subject: Always allocate JACK ringbuffers. This makes sure a program using this library would not segfault while waiting for a stopped JACK server to autostart. --- RtMidi.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/RtMidi.cpp b/RtMidi.cpp index ce6db63..1287afa 100644 --- a/RtMidi.cpp +++ b/RtMidi.cpp @@ -2678,6 +2678,10 @@ void MidiOutJack :: connect() JackMidiData *data = static_cast (apiData_); if ( data->client ) return; + + // Initialize output ringbuffers + data->buffSize = jack_ringbuffer_create( JACK_RINGBUFFER_SIZE ); + data->buffMessage = jack_ringbuffer_create( JACK_RINGBUFFER_SIZE ); // Initialize JACK client if (( data->client = jack_client_open( clientName.c_str(), JackNoStartServer, NULL )) == 0) { @@ -2687,8 +2691,6 @@ void MidiOutJack :: connect() } jack_set_process_callback( data->client, jackProcessOut, data ); - data->buffSize = jack_ringbuffer_create( JACK_RINGBUFFER_SIZE ); - data->buffMessage = jack_ringbuffer_create( JACK_RINGBUFFER_SIZE ); jack_activate( data->client ); } @@ -2696,12 +2698,12 @@ MidiOutJack :: ~MidiOutJack() { JackMidiData *data = static_cast (apiData_); closePort(); - + + // Cleanup + jack_ringbuffer_free( data->buffSize ); + jack_ringbuffer_free( data->buffMessage ); if ( data->client ) { - // Cleanup jack_client_close( data->client ); - jack_ringbuffer_free( data->buffSize ); - jack_ringbuffer_free( data->buffMessage ); } delete data; -- cgit v1.2.3