我使用此代码运行应用程序时有时会出现错误代码:
let letstryOtherThing: @convention(c) (UnsafeMutablePointer<MIDISysexSendRequest>) -> Swift.Void =
{ plop in
print("here")
}
let rawPointer = UnsafeRawPointer([0xF0, 0x20, 0x21, 0x22, 0x23, 0xF7])
let pointer = rawPointer.assumingMemoryBound(to: UInt8.self)
let bytesToSend: UInt32 = 60
let complete: DarwinBoolean = false
let completionProc: MIDICompletionProc? = letstryOtherThing
let completionRefCon: UnsafeMutableRawPointer? = nil
let data: UnsafePointer<UInt8> = pointer
let destination: MIDIEndpointRef = dest!
let reserved: (UInt8, UInt8, UInt8) = (0, 0 ,0)
var midiRequest:MIDISysexSendRequest = MIDISysexSendRequest(destination: destination, data: data, bytesToSend: bytesToSend, complete: complete, reserved: reserved, completionProc: completionProc!, completionRefCon: completionRefCon)
DispatchQueue.main.async(execute: {
MIDISendSysex(&midiRequest)
})
代码是:
EXC_BAD_ACCESS(代码= 1,地址= 0x800000020)。
如果有人有想法,我会使用CoreMidi库。
答案 0 :(得分:0)
我发现了问题。 这是因为这个var是本地的,它必须在全局声明它。
var midiRequest:MIDISysexSendRequest = MIDISysexSendRequest(destination: destination, data: data, bytesToSend: bytesToSend, complete: complete, reserved: reserved, completionProc: completionProc!, completionRefCon: completionRefCon)