QMidi icon indicating copy to clipboard operation
QMidi copied to clipboard

sendSysEx() on Mac OSX

Open denisgottardello opened this issue 4 years ago • 8 comments

Hi, my program works well in Linux and Windows. It goes to crash on Mac OS X. After a debug session I can't find the bug. I can send not more than one or two midi massage (on Mac OS X). My opinion is that MIDISendSysex() function is async. Does anyone had the same problem?

denisgottardello avatar Oct 28 '20 15:10 denisgottardello

Could you provide some information on your problem? Useful would be

  • steps to reproduce / minimal example
  • what did you try?

LeStahL avatar Oct 28 '20 15:10 LeStahL

CC @CodeforEvolution.

waddlesplash avatar Oct 28 '20 16:10 waddlesplash

Please try it http://www.denisgottardello.it/Test01.zip On windows and Linux no problem. On Mac OS X sometimes works, sometimes goes to crash.

denisgottardello avatar Oct 28 '20 17:10 denisgottardello

You might be right - the request is made with a reference to a temporary (from your functions on_pushButton_clicked and on_pushButton_2_clicked), which is likely the cause for the crash. Those will return and the result of HexStringToByteArray(ui->lineEditNoteOn->text()) becomes invalid - and so does request.data.

Possible options:

  • Don't call sendSysEx on temporaries in your non-QMidi code.
  • Change QMidi_CoreMidi.cpp to alloc and copy the bytes, then use the completionProc of the request to free them again.

I do not have OS X available for testing, so I'm not the right person to implement such a thing ;)

LeStahL avatar Oct 28 '20 22:10 LeStahL

Solved by changing the code ` MIDISysexSendRequest request; request.bytesToSend = data.length(); request.complete = false; request.completionProc = nullptr; request.completionRefCon = nullptr; request.data = (Byte *)data.constData(); request.destination = fMidiPtrs->destinationId;

MIDISendSysex(&request);`

to ` MIDISysexSendRequest *request= new MIDISysexSendRequest(); request->bytesToSend = data.length(); request->complete = false; request->completionProc = nullptr; request->completionRefCon = nullptr; request->data = (Byte *)data.constData(); request->destination = fMidiPtrs->destinationId;

MIDISendSysex(request);`

When can I delete the object request ? On compile time I have a lot of warnings. Can I add as developer or there is anyone that will improve the code?

denisgottardello avatar Oct 29 '20 14:10 denisgottardello

request->completionProc can be used to delete request again, after passing the pointer there with request->completionRefCon

refer to https://developer.apple.com/documentation/coremidi/midisysexsendrequest

completionProc will be called when you can delete the request.

LeStahL avatar Oct 29 '20 14:10 LeStahL

Can I add as developer

@waddlesplash would have to answer that. :)

LeStahL avatar Oct 29 '20 14:10 LeStahL

You can submit a pull request with this, sure. It would be best if the warnings were fixed, and of course you need to write the callback to delete the request.

waddlesplash avatar Oct 29 '20 14:10 waddlesplash