QMidi
QMidi copied to clipboard
sendSysEx() on Mac OSX
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?
Could you provide some information on your problem? Useful would be
- steps to reproduce / minimal example
- what did you try?
CC @CodeforEvolution.
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.
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 thecompletionProc
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 ;)
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?
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.
Can I add as developer
@waddlesplash would have to answer that. :)
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.