Swift 2中带有MusicSequenceBarBeatTimeToBeats的EXEC_BAD_INSTRUCTION(代码= 1,地址= 0xe)

时间:2016-02-25 12:24:22

标签: swift2 unsafe-pointers c-api musicsequence

在Swift 2中使用Apples MusicSequence C API时遇到问题。我无法在调用MusicSequenceBarBeatTimeToBeats时弄清楚如何摆脱EXEC_BAD_INSTRUCTION。

我在互联网上尝试了很多不同的解决方案,但似乎没有任何效果。

我的第一次尝试没有导致编译错误:

import Cocoa
import AudioToolbox

var musicSequence = MusicSequence()

NewMusicSequence(&musicSequence)

var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp: MusicTimeStamp = 0

MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, &musicTimeStamp)

The result is: EXEC_BAD_INSTRUCTION (code=1, address=0xe) at the MusicSequenceBarBeatTimeToBeats code row

然后我尝试了这个,但结果相同:

var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp = UnsafeMutablePointer<MusicTimeStamp>.alloc(sizeof(MusicTimeStamp))

MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, musicTimeStamp)

musicTimeStamp.dealloc(sizeof(MusicTimeStamp))

我尝试了withUnsafeutablePointer函数,但运行时错误相同:

var barBeatTime = CABarBeatTime(bar: 1, beat: 1, subbeat: 0, subbeatDivisor: 960, reserved: 0)
var musicTimeStamp: MusicTimeStamp = 0

withUnsafeMutablePointer(&musicTimeStamp,
{
    MusicSequenceBarBeatTimeToBeats(musicSequence, &barBeatTime, UnsafeMutablePointer($0))
})

如果我在第三个参数中传递nil它不会崩溃,但这是没用的,因为缺少输出。所以它似乎是问题的UnsafeMutablePointer<MusicTimeStamp>输出参数。

MusicSequenceBarBeatTimeToBeats(musicSequence, &caBarBeatTime, nil)

有什么建议吗?

0 个答案:

没有答案