0
0

Hi!

I wrote about this problem in a previous post, but i merged two problems and now I want explain one of theese correctly.

I’m having a segmentation fault in this callback function:
[code:2r1uxkog]

FMOD_System **ssystem; //global variable

FMOD_RESULT cb_sound(FMOD_CHANNEL *channel,
FMOD_CHANNEL_CALLBACKTYPE FMOD_CHANNEL_CALLBACKTYPE_END,
void *data1, void *data2)
{
dlsystem dsystem;
unsigned int id;
char url[64];
static int status = 0;
FMOD_RESULT ret;

    FMOD_System_GetUserData(ssystem, (void**)&dsystem);

    if(dsystem->dsound->sound != NULL) {
        LOG("CALLBACK OFF", NULL);
        FMOD_Channel_SetCallback(dsystem->dsound->channel, NULL);
        FMOD_Sound_Release(dsystem->dsound->sound);
    }

    while(ret != FMOD_OK) {
        if(dsystem->dsound->id != 0) {
            free_sound(dsystem->dsound);
        }
        sql_extract_data(dsystem);
        snprintf(url, sizeof(url)-1, "http://www.devicelost.com/mp3/0/%d.mp3", dsystem->dsound->id);
        ret = FMOD_System_CreateStream(ssystem, url, FMOD_SOFTWARE | FMOD_2D, 0 ,&dsystem->dsound->sound);
        if(ret != FMOD_OK)
            fprintf(stderr, "Create stream: %s\n", FMOD_ErrorString(ret));
    }
    LOG("CREATE STREAM", NULL);

    ret = FMOD_System_PlaySound(ssystem, FMOD_CHANNEL_FREE, dsystem->dsound->sound, 0, &dsystem->dsound->channel);
    if( ret != FMOD_OK ) {
        LOG("FMOD ERROR:", FMOD_ErrorString(ret));
        return 1;
    }

    LOG("PLAYING SOUND", NULL);
    FMOD_System_SetUserData(ssystem, dsystem);  
    FMOD_Channel_SetCallback(dsystem->dsound->channel, (FMOD_CHANNEL_CALLBACK)cb_sound);
    FMOD_Channel_SetVolume(dsystem->dsound->channel, 0.1);
    LOG("CALLBACK ON", NULL);

    return 0;

}[/code:2r1uxkog]

This function is called when sound stops(song terminated). It works for two times, in third case, it crash:

[code:2r1uxkog]Agnostic Front
Belive
1270582340
CREATE STREAM –
PLAYING SOUND –
CALLBACK ON –

CALLBACK OFF –
Release dlsound –
Resurrección
Xhelazz
Pro sin par (con Eric B)
1276941380
CREATE STREAM –
PLAYING SOUND –
CALLBACK ON –

CALLBACK OFF –
Release dlsound –
Nokturnal Mortum
Nokturnal Mortum – Under the Banner of the Horned Knjaz
1276942354
CREATE STREAM –
PLAYING SOUND –
CALLBACK ON –
Violación de segmento
[/code:2r1uxkog]

Really, i read code infinity of times, and i don’t see the error. I don’t understand… i feel stupid.
Can you help me? I would greatly appreciate

Regards

  • You must to post comments
0
0

Thanks for reading Peter.

Regards

  • You must to post comments
0
0

I’ve been thinking about it, and I think that i just know why my aplication crashes with segfault.
In FMOD manual, specify this about [b:1b5s70a1]Sound::Release[/b:1b5s70a1]:

[quote:1b5s70a1]This will free the sound object and everything created under it.[/quote:1b5s70a1]

If i understand good, this mean that when I release the sound, channel also is destroyed, and callback is called through channel.
If sound is destroyed, also channel is destroyed, and then the callback has a bad behaviour.

It’s true?

Thanks a lot

  • You must to post comments
0
0

Yes that is correct, FMOD is [i:2iqodtfh]almost[/i:2iqodtfh] finished with the Sound

  • You must to post comments
0
0

Hello Peter, thanks for answer me.

I’ve arranged the part of callback code. (CALLBACKTYPE).

But the about the segfault… i don’t understand why this is happening.

I’m asume that when callback is called is because sound is already stopped, and fmod doesn’t need it any more.
This is the why i release the sound, and then create a new sound in a "playnext" function.

Why is not safe to be done in these way? Because is done into a function that doesn’t create it?

Thanks!

  • You must to post comments
0
0

This code is wrong:
[code:153mr0mp] FMOD_CHANNEL_CALLBACKTYPE FMOD_CHANNEL_CALLBACKTYPE_END, [/code:153mr0mp]

You want to do something like this:

[code:153mr0mp]FMOD_RESULT cb_sound(FMOD_CHANNEL *channel,
FMOD_CHANNEL_CALLBACKTYPE callbackType,
void *data1, void *data2)
{
if (callbackType == FMOD_CHANNEL_CALLBACKTYPE_END)
{
//...
}
}[/code:153mr0mp]

This is wrong:
[code:153mr0mp] FMOD_Sound_Release(dsystem->dsound->sound);[/code:153mr0mp]

You [b:153mr0mp]cannot[/b:153mr0mp] release the sound inside the channel end callback! This is not safe and probably the cause of your seg fault.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.