Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seg Fault sometimes when OPL3_Reset is called #22

Open
fawtytoo opened this issue Nov 16, 2022 · 1 comment
Open

Seg Fault sometimes when OPL3_Reset is called #22

fawtytoo opened this issue Nov 16, 2022 · 1 comment

Comments

@fawtytoo
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant