0
0

I am playing 2 sounds at the same time using 2 different channels. If you start playing the sounds, and hit the back button, both need to stop.

My issue is that if sound A is shorter than sound B, and I hit back after A has finished and B is still playing, or I hit back after both are finished, I get the error: "FMOD error! (36) An invalid object handle was used."

If I hit back before I play the sounds, it works fine because "if(channel)" never triggers; but after they play and finish channel is valid but crashes at the isPlaying line.

Here is my method for stopping playback:

[code:3k5kkau3]

//==========================================================================
– (void)stopWave
{
FMOD_RESULT result = FMOD_OK;
bool isPlaying;

if(channel)
{
    result = channel->isPlaying(&isPlaying);
    ERRCHECK(result);


    if(isPlaying) 
    {
        result = channel->stop();
        ERRCHECK(result);
    }

}
if(channel2)
{
    result = channel2->isPlaying(&isPlaying);
    ERRCHECK(result);


    if(isPlaying) 
    {
        result = channel2->stop();
        ERRCHECK(result);
    }

}

}

[/code:3k5kkau3]

Any help greatly appreciated!

  • You must to post comments
0
0

If I remove the ERRCHECK(result) from each of my results it runs as I want it to with no crashes (stops both audio files); is this bad practice?

  • You must to post comments
0
0

Firstly this isn’t a crash, it’s an error condition, the error is saying the channel you are trying to access is already stopped and become invalid. Then the ERRCHECK function is causing the program to exit.

You could ignore FMOD_ERR_INVALID_HANDLE in this case, it’s not a terminal error, this would simplify your code and still be acceptable because you simply want the channel stopped, you don’t care that it is actually already stopped. Your code could just be:

[code:3vkqpa0u]- (void)stopWave
{
channel->stop();
channel2->stop();
}[/code:3vkqpa0u]

  • You must to post comments
0
0

[quote="mathew":ieo0v5d6]Firstly this isn’t a crash, it’s an error condition, the error is saying the channel you are trying to access is already stopped and become invalid. Then the ERRCHECK function is causing the program to exit.

You could ignore FMOD_ERR_INVALID_HANDLE in this case, it’s not a terminal error, this would simplify your code and still be acceptable because you simply want the channel stopped, you don’t care that it is actually already stopped. Your code could just be:

[code:ieo0v5d6]- (void)stopWave
{
channel->stop();
channel2->stop();
}[/code:ieo0v5d6][/quote:ieo0v5d6]

Makes sense, thanks!

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.