djipco / webmidi

Tame the Web MIDI API. Send and receive MIDI messages with ease. Control instruments with user-friendly functions (playNote, sendPitchBend, etc.). React to MIDI input with simple event listeners (noteon, pitchbend, controlchange, etc.).
Apache License 2.0
1.54k stars 116 forks source link

NodeJS process with WebMIDI crashes upon closing Max 8, if Max was started before starting the NodeJS process #391

Open nnirror opened 1 year ago

nnirror commented 1 year ago

Description

My nodeJS process crashes when I include WebMIDI, under the following circumstance:

I first open Max 8, then start a nodeJS process, and then close Max.

Environment: Specify the environment where you are witnessing the problem:

Details

Here's the contents of a nodeJS process that's crashing on my machine. This test.js file contains only:

const {WebMidi} = require('webmidi');
WebMidi.enable();

Steps to reproduce:

  1. open Max 8.
  2. start the node process: node test.js
  3. close Max 8.

I see the following error in the console, and I see that the nodeJS process thread has terminated.

Segmentation fault: 11

I checked that the same workflow does not cause a crash with Ableton Live 11.

djipco commented 1 year ago

WEBMIDI.js uses the jzz package under the hood for MIDI communication on Node.js. Could you install the module and try this basic example to see if you get the same problem:

const navigator = require('jzz'); 

navigator.requestMIDIAccess({sysex: true}).then((access)=>{
  console.log(Array.from(access.inputs.values()), Array.from(access.outputs.values())); 
}, (err)=>{console.log(err)});

Thanks!

P.S. It might be related to this: https://github.com/jazz-soft/JZZ/issues/49 (follow-up here: https://github.com/jazz-soft/jazz-midi/issues/5)

nnirror commented 1 year ago

@djipco Yes, I do get the exact same error in a test npm project that only has jzz 1.7.4 installed. When I open Max, start the Node process, and then close Max, I get Segmentation fault: 11.

djipco commented 1 year ago

Thanks for reporting back. It is quite clear now that the issue is with the jazz-midi module. I have notified the jazz-midi team of the problem. We will have to wait for them for a resolution.