EXC_BAD_ACCESS(代码= 1,地址= 0x0)

时间:2012-09-19 18:18:24

标签: xcode macos

EXEC_BAD_ACCESS(Code=1 , Address 0x0)此代码位于applicationDidFinishLaunching之后的Appledelegate.m中。 偶然循环的随机循环(如果查找事件很少,不会出现异常)。对不起语言和感谢任何帮助我... 现在来源:

int trackindex = 14;
MusicSequenceGetIndTrack(sequence,trackindex, &track);

// Iterate throught the select track and add user event
Boolean hasNextEvent = false;
Boolean hasEvent = false;
NewMusicEventIterator(track,&iterator);
MusicEventIteratorHasCurrentEvent(iterator, &hasEvent);
MusicEventIteratorHasNextEvent(iterator, &hasNextEvent);

// loop throught track
while (hasNextEvent==true){
    MusicTimeStamp timestamp = 0;
    MusicEventType eventType = 0;
    const void *eventData = NULL;
    int note = 0;
    MusicTimeStamp duration = 0;
    MusicEventIteratorGetEventInfo(iterator, &timestamp, &eventType, &eventData, NULL);

    if(eventType == kMusicEventType_MIDINoteMessage) {
        MIDINoteMessage *noteMessage = (MIDINoteMessage *)eventData;
        note = noteMessage->note;
        duration = noteMessage->duration;
        UserEvent event;

        event.lenght = 0;
        event.lenght = sizeof(UserEvent);
        event.playedNote = note;
        event.tStamp = timestamp;

        MusicEventUserData *data = (MusicEventUserData *)&event;
        MusicTrackNewUserEvent((MusicTrack)track, timestamp, data);

        counter++;
        printf("counter : %u\n",counter);
    }

    MusicEventIteratorHasNextEvent(iterator, &hasNextEvent);
    MusicEventIteratorNextEvent(iterator);
}

1 个答案:

答案 0 :(得分:0)

引起我注意的第一件事是“while(hasNextEvent == true)”与“while(hasNextEvent)”不同。

第二个是,在你的循环结束时,你采用迭代器的“hasNextEvent”然后在检查状态之前推进它似乎很奇怪。不确定这是错的,但看起来不对。