swift - 可能是指针错误 Midi sysEx

标签 swift runtime-error coremidi

当我使用以下代码运行应用程序时,有时会出现错误代码:

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/

相关文章:

swift - 如何在 Swift 中通过实际类型限制 switch case

ios - Swift - 类型 'CircularTransition' 不符合协议(protocol) 'UIViewControllerAnimatedTransitioning'

java - Android Studio : Session 'MainActivity' : error, 但是没有报错

c++ - VC++ 运行时错误 : Debug Assertation Failed

iphone - iOS 的 MIDI 文件播放库

swift - 如何使用 CoreMidi 创建带有 Channel 的 MidiEventPacket?

ios - 如何在 Swift 中打印格式化的 Decimal 值?

ios - NSURL - 用空格编码 '&'

c - 如何调试 0xc0000417 退出代码的原因

ios - CoreMidi 十六进制值