当我使用以下代码运行应用程序时,有时会出现错误代码:
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 (code=1, address=0x800000020).
如果有人有想法,我会使用 CoreMidi 库。
最佳答案
我发现了问题。 这是因为这个变量是本地的,需要在全局中声明它。
var midiRequest:MIDISysexSendRequest = MIDISysexSendRequest(destination: destination, data: data, bytesToSend: bytesToSend, complete: complete, reserved: reserved, completionProc: completionProc!, completionRefCon: completionRefCon)
关于swift - 可能是指针错误 Midi sysEx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47017150/