Nuked-OPL3 icon indicating copy to clipboard operation
Nuked-OPL3 copied to clipboard

Seg Fault sometimes when OPL3_Reset is called

Open fawtytoo opened this issue 2 years ago • 1 comments

I've written my own midi player called Midiplay and am currently using Nuked for synthesizing the output. Each time I change midi tracks, I call OPL3_Reset, but it can (but not always) cause a Seg Fault. The solution was to call OPL3_Reset only once during Midiplay's initialisation. Then, during track initialisation:

    opl3_chip   oplChip;
    int i;

    for (i = 0; i < 18; i++)
    {
        oplChip.channel[i].cha = 0;
        oplChip.channel[i].chb = 0;
    }

    oplChip.writebuf_samplecnt = 0;
    oplChip.writebuf_cur = 0;
    oplChip.writebuf_last = 0;
    oplChip.writebuf_lasttime = 0;
    for (i = 0; i < OPL_WRITEBUF_SIZE; i++)
    {
        oplChip.writebuf[i].reg = 0;
    }

Perhaps it would be advantageous to have an OPL3_Init function. Then OPL3_Reset could just do the minimal stuff. Notice that I've initialised left & right channels to zero to silence them.

fawtytoo avatar Nov 16 '22 14:11 fawtytoo

The segfault was due to Midiplay resetting the track information before resetting the channels first. SDL callbacks are tricky things.

fawtytoo avatar Apr 29 '24 10:04 fawtytoo