0
0

Hi to all.
I have this simple piece of code:

[code:3ouvbvjn]bool *playing = false;
if( channel != NULL )
{
FMOD_RESULT result = channel->isPlaying(playing);
SoFMODSystem::ERRCHECK(result, FILE, LINE);

 if( (playing == false) || (loopMode == false) )
     return;

}
else cout << "no channel" << endl;[/code:3ouvbvjn]

The Channel::isPlaying give to me a segmentation fault and I don’t understad why :(.
If I comment it I don’t get the seg fault.
Can I have a help?
Regards,
Franco

  • You must to post comments
0
0

You’ve got there "bool * playing = false". Your code should be something like:

[code:1tlvnil1]bool playing = false;
channel->isPlaying(&playing);[/code:1tlvnil1]

  • You must to post comments
0
0

[quote="Adiss":2rwama05]You’ve got there "bool * playing = false". Your code should be something like:

[code:2rwama05]bool playing = false;
channel->isPlaying(&playing);[/code:2rwama05][/quote:2rwama05]
Yes sorry was my mistake but the problem is that I don’t understand why this code

[code:2rwama05]bool playing = false;
if( channel )
{
FMOD_RESULT result = channel->isPlaying(&playing);
SoFMODSystem::ERRCHECK(result, FILE, LINE);

 if( playing == false )
     return;

}
else cout << "no channel" << endl;[/code:2rwama05]

gives this FMOD error:

[code:2rwama05]FMOD error! (36) An invalid object handle was used[/code:2rwama05]
at the line
[code:2rwama05]FMOD_RESULT result = channel->isPlaying(playing);[/code:2rwama05]

I think if the channel is not valid the "return" statement must be executed istead of the Channel::isPlaying().
Any idea?
Regards,
Franco

  • You must to post comments
0
0

When you say:
if(channel)
You’re just checking the value of the Channel*, which you presumably got from System::playsound(). The value of that pointer isn’t going to change, unless you do so yourself.

So, even if your channel gets invalidated (by getting stolen, you stopping it, or whatever), the value of the pointer that you’ve stored is still nonzero, which is what you’re checking against.

  • You must to post comments
0
0

[quote="Adiss":2ica9lkq]When you say:
if(channel)
You’re just checking the value of the Channel*, which you presumably got from System::playsound(). The value of that pointer isn’t going to change, unless you do so yourself.

So, even if your channel gets invalidated (by getting stolen, you stopping it, or whatever), the value of the pointer that you’ve stored is still nonzero, which is what you’re checking against.[/quote:2ica9lkq]

Hi Adiss.
Yes I think the problem is that the channel is getting stolen. How can I solve this case? I have class wrote using the fmod api and I would do that a single object can play more than 1 sound. Must I have a list/vector of channels and a list/vector of sounds? Is there any example doing this? Or can you help me with some line of code or pseudo code?
Can a channel play more than 1 sound? Or I must have a channel per sound?
Regards,
Franco

  • You must to post comments
0
0

[quote:z7bxx6r9]Or I must have a channel per sound? [/quote:z7bxx6r9]
One channel per sound.

The invalid channel handle error is common. You can set a channel callback to null the pointer or remove it from the list or what ever you like.

[quote:z7bxx6r9]a single object can play more than 1 sound … Must I have a list/vector of channels[/quote:z7bxx6r9]
Yes, your object must contain something like this to play many sounds at once. You shouldn’t be creating a FMOD::Sound instance per object because you only need one instance (unless it is streaming).

  • You must to post comments
0
0

[quote="PeterStirling":k0tzbhyw]
One channel per sound. [/quote:k0tzbhyw]
Thanx

[quote:k0tzbhyw]The invalid channel handle error is common. You can set a channel callback to null the pointer or remove it from the list or what ever you like.
[/quote:k0tzbhyw]
How? Can I have a little example or pseudo code please?

[quote:k0tzbhyw]Yes, your object must contain something like this to play many sounds at once. You shouldn’t be creating a FMOD::Sound instance per object because you only need one instance (unless it is streaming).[/quote:k0tzbhyw]
Sorry but I didn’t understand. I have many objects playing sound tracks. Every object plays at least 1 sound, and may be a single object plays more than 1

  • You must to post comments
0
0

[quote:18yi6d5c]How? Can I have a little example or pseudo code please? [/quote:18yi6d5c]

From [b:18yi6d5c]fmodex.chm[/b:18yi6d5c]
[code:18yi6d5c]FMOD_RESULT Channel::setCallback(
FMOD_CHANNEL_CALLBACK callback
);[/code:18yi6d5c]
[code:18yi6d5c]
FMOD_RESULT F_CALLBACK mycallback(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type, unsigned int commanddata1, unsigned int commanddata2)
{
FMOD::Channel *cppchannel = (FMOD::Channel *)channel;

// More code goes here.

return FMOD_OK;
}[/code:18yi6d5c]

[quote:18yi6d5c]Sorry but I didn’t understand.[/quote:18yi6d5c]
You can play a single FMOD::Sound on multiple FMOD::Channels:
[code:18yi6d5c]FMOD::Sound *sound1;
FMOD::Channel *channel1, *channel2;

ERRCHECK(result = system->createSound("c:\media\drumloop.wav", FMOD_DEFAULT, 0, &sound1));

FMOD_RESULT System::playSound(FMOD_CHANNEL_FREE, sound1, false, &channel1);
FMOD_RESULT System::playSound(FMOD_CHANNEL_FREE, sound1, false, &channel2);[/code:18yi6d5c]

  • You must to post comments
0
0

[quote="PeterStirling":3t9r12if][quote:3t9r12if]How? Can I have a little example or pseudo code please? [/quote:3t9r12if]

From [b:3t9r12if]fmodex.chm[/b:3t9r12if]
[code:3t9r12if]FMOD_RESULT Channel::setCallback(
FMOD_CHANNEL_CALLBACK callback
);[/code:3t9r12if]
[code:3t9r12if]
FMOD_RESULT F_CALLBACK mycallback(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type, unsigned int commanddata1, unsigned int commanddata2)
{
FMOD::Channel *cppchannel = (FMOD::Channel *)channel;

// More code goes here.

return FMOD_OK;
}[/code:3t9r12if]

[quote:3t9r12if]Sorry but I didn’t understand.[/quote:3t9r12if]
You can play a single FMOD::Sound on multiple FMOD::Channels:
[code:3t9r12if]FMOD::Sound *sound1;
FMOD::Channel *channel1, *channel2;

ERRCHECK(result = system->createSound("c:\media\drumloop.wav", FMOD_DEFAULT, 0, &sound1));

FMOD_RESULT System::playSound(FMOD_CHANNEL_FREE, sound1, false, &channel1);
FMOD_RESULT System::playSound(FMOD_CHANNEL_FREE, sound1, false, &channel2);[/code:3t9r12if][/quote:3t9r12if]

Peter I followed your suggestions and wrote this code:

[code:3t9r12if]FMOD_RESULT F_CALLBACK endCallback(FMOD_CHANNEL *channel,
FMOD_CHANNEL_CALLBACKTYPE type,
unsigned int commanddata1,
unsigned int commanddata2)
{
FMOD_RESULT result;
FMOD::Channel *currentChannel = (FMOD::Channel *)channel;

currentChannel = 0;

cout << "Value of channel " << currentChannel << " – Value of passed channel: " << channel << endl;

return FMOD_OK;
}[/code:3t9r12if]

Where I want to null the channel bust seems that this doesn’t have effect because I still have the error. The channel is part of my sound class and I would null it when the sound finish. Internally to the call back there is a copy of the pointerso I have to do something as MYSOUNDCLASS::thepassedChannel = null.
How can I do it internally the callback? I would pass the pointer to the channel that’s part of the sound class. Can you help me?
Regards,
Franco
But strangely the cout give to different values.

  • You must to post comments
0
0

[quote:l0alwii6] currentChannel = 0;[/quote:l0alwii6]

Instead of setting the FMOD channel pointer from the callback to zero, you should be setting your own channel pointer to zero. So you need to know where [i:l0alwii6]your[/i:l0alwii6] channel pointer is inside the callback.
[code:l0alwii6]SoundClass->channel = 0[/code:l0alwii6]
To do this you need to know which instance of the SoundClass the current channel belongs to. This is a situation where you can use channel->setUserData, and channel->getUserData.

So whenever you create a new channel you want to make sure the "user data" of that channel is pointing back to your class.

something like this:

system->playSound(FMOD_CHANNEL_FREE, Sound, false, &channel)
channel->setUserData((void *) this); //set the user data

then inside the callback you can do something like this:

[code:l0alwii6]void *data;
currentChannel->getUserData(data); //get the user data
((SoundManager *)data)->channel = NULL;
[/code:l0alwii6]

Now the SoundClass->channel pointer is set to zero and the code from the first post will work as expected
[code:l0alwii6]
if( channel != NULL )
[/code:l0alwii6]

  • You must to post comments
0
0

[quote="PeterStirling":2xa7bmin][quote:2xa7bmin] currentChannel = 0;[/quote:2xa7bmin]

Instead of setting the FMOD channel pointer from the callback to zero, you should be setting your own channel pointer to zero. So you need to know where [i:2xa7bmin]your[/i:2xa7bmin] channel pointer is inside the callback.
[code:2xa7bmin]SoundClass->channel = 0[/code:2xa7bmin]
To do this you need to know which instance of the SoundClass the current channel belongs to. This is a situation where you can use channel->setUserData, and channel->getUserData.

So whenever you create a new channel you want to make sure the "user data" of that channel is pointing back to your class.

something like this:

system->playSound(FMOD_CHANNEL_FREE, Sound, false, &channel)
channel->setUserData((void *) this); //set the user data

then inside the callback you can do something like this:

[code:2xa7bmin]void *data;
currentChannel->getUserData(data); //get the user data
((SoundManager *)data)->channel = NULL;
[/code:2xa7bmin]

Now the SoundClass->channel pointer is set to zero and the code from the first post will work as expected
[code:2xa7bmin]
if( channel != NULL )
[/code:2xa7bmin][/quote:2xa7bmin]

Thanx it works

  • You must to post comments
Showing 10 results
Your Answer

Please first to submit.