samedi 19 septembre 2020

Seg Fault from the following function in cs302-midi.cpp

I'm running the following function to manipulate MIDI files, but keep getting a seg fault

./gradescript: line 38: 26596 Segmentation fault (core dumped) ./$program $ge/$enum.txt tmp-$enum-test-output.txt $format > tmp-$enum-test-stdout.txt 2> tmp-$enum-test-stderr.txt

Here is my void function below:

void CS302_Midi::el_to_nd(){
nd = new NDMap;

//Keeps track of the total time to insert into ND
double timeSinceStart = 0; 

//Temp pointers
vector<ND*> tmp(128, NULL);
ND *note, *damper;
Event *event;

for(EventList::iterator it = el->begin(); it != el->end(); it++){
    event = *it;
    timeSinceStart += (event->time/480.0);

    //Encountered On Event
    if(event->key == 'O'){  
        note = new ND;
        //Stores time relative to total time
        note->start = timeSinceStart;
        note->pitch = event->v1;
        note->volume = event->v2;
        note->key = 'N';
        //Store note based off pitch(index)
        tmp[note->pitch] = note;
    }

    //Encountered OFF Event
    if(event->key == 'F'){
        note = tmp[event->v1];
        note->stop = timeSinceStart;
        nd->insert(make_pair(note->start, note));
        tmp[event->v1] = NULL;
    }

    //DamperDown Event
    if(event->key == 'D' && event->v1 == 1){
        damper = new ND;
        damper->key = 'D';
        damper->start = timeSinceStart;
        tmp[0] = damper;
    }

    //DamperUp Event 
    if(event->key == 'D' && event->v1 == 0){
        damper = new ND;
                    damper = tmp[0];
        damper->stop = timeSinceStart;
        nd->insert(make_pair(damper->start, damper));
    }
}

}

Aucun commentaire:

Enregistrer un commentaire