0
0

Hi,

we’re currently working to see if we can get good quality and stable sound for our project by using fmod. However we’ve run into a problem thats proving hard to trace.

At the moment when starting our program it is quite like a lottery what result you’ll get..

Possibility 1: the program starts fine, runs fine and sound is great

Possibility 2: the program hangs when (or shortly after) trying to initialise fmod

Possibility 3: the program segfaults in fmod

last observed stack traces:
(gdb) bt

0 0x406f1ddd in FMOD::Thread::callback () from /usr/local/lib/libfmodex.so

1 0x406f1d88 in FMOD::Thread::callback () from /usr/local/lib/libfmodex.so

2 0x402237f3 in start_thread () from /lib/tls/libpthread.so.0

3 0x4099d62a in clone () from /lib/tls/libc.so.6

(gdb)

(gdb) bt

0 0x402224fb in sem_wait@GLIBC_2.0 () from /lib/tls/libpthread.so.0

1 0x406eccbe in FMOD_OS_Semaphore_Wait () from /usr/local/lib/libfmodex.so

2 0x4000c9f0 in _dl_runtime_resolve () from /lib/ld-linux.so.2

3 0x406eae25 in FMOD::Thread::callback () from /usr/local/lib/libfmodex.so

4 0x406ead88 in FMOD::Thread::callback () from /usr/local/lib/libfmodex.so

5 0x4021e7f3 in start_thread () from /lib/tls/libpthread.so.0

6 0x4099362a in clone () from /lib/tls/libc.so.6

(gdb)

(but I’ve also seen one where gdb seemed to complain about a corrupt stack frame)

Added difficulty in tracking the above behavior is that it’s not really reproduceable. One moment it always segfaults, the next I cant get it to segfault. Also, starting it in the debugger will again change behavior.

Please note that when configured to not use fmod (but sdl or openal) this program is quite stable.

It looks like there could be some uninitialised memory being that should really be initialised, or a stack frame being overwritten somewhere. But at the moment it’s quite hard to track (valgrind also doesnt seem to give any pointers to anything that could cause this).

If anyone has an idea what we could be doing wrong to cause this in fmod, or how to better track what’s going wrong that would be highly appreciated.

(The two test machines both run SuSE 9.2, both are SMP (one Athlon XP, one Xeon em64t) and have different soundcards. The problem is the same when using either 4.03.04 and 4.03.07)

  • You must to post comments
0
0

not with the latest version, but with older versions, yes. no problems at all.

  • You must to post comments
0
0

not that i can see, this is our init code:

[quote:26p440vi]
FMOD_RESULT result ;
uint version ;

    result = FMOD::System_Create (&g_fmod_system) ;
    if (result != FMOD_OK)
    {
        printf ("FMOD error in System_Create: %s (%d)\n", FMOD_ErrorString (result), result) ;
        return (false) ;
    }

    result = g_fmod_system->getVersion (&version) ;
    if (result != FMOD_OK)
    {
        printf ("FMOD error in getVersion: %s (%d)\n", FMOD_ErrorString (result), result) ;
        g_fmod_system->release () ;
        return (false) ;
    }
    if (version < FMOD_VERSION)
    {
        printf ("Error!  You are using an old version of FMOD %08x.  This program requires %08x\n", ver
        g_fmod_system->release () ;
        return (false) ;
    }

    result = g_fmod_system->setOutput (FMOD_OUTPUTTYPE_ALSA) ;
    if (result != FMOD_OK)
    {
        printf ("FMOD error in setOutput: %s (%d)\n", FMOD_ErrorString (result), result) ;
        g_fmod_system->close () ;
        g_fmod_system->release () ;
        return (false) ;
    }

    result = g_fmod_system->init (32, FMOD_INIT_NORMAL, 0);
    if (result != FMOD_OK)
    {
        printf ("FMOD error in init: %s (%d)\n", FMOD_ErrorString (result), result) ;
        g_fmod_system->close () ;
        g_fmod_system->release () ;
        return (false) ;
    }

[/quote:26p440vi]

The only thing I added after checking it was setOutput to ALSA. Which incidentally added the following error as a new possibility:

our_binary: pcm.c:1135: snd_pcm_writei: Assertion Size == 0 || buffer’ failed.
Aborted
(gdb) bt

0 0xffffe410 in ?? ()

1 0x458a984c in ?? ()

2 0x00000006 in ?? ()

3 0x00002585 in ?? ()

4 0x40902d41 in raise () from /lib/tls/libc.so.6

5 0x40904529 in abort () from /lib/tls/libc.so.6

6 0x408fc573 in __assert_fail () from /lib/tls/libc.so.6

7 0x405fcba2 in snd_pcm_link_ptr () from /usr/lib/libasound.so.2

8 0x406eed65 in FMOD::OutputALSA::updateMixer () from

/usr/local/lib/libfmodex.so

9 0x40679304 in ?? () from /usr/local/lib/libfmodex.so

(gdb)

  • You must to post comments
0
0

possibly found the problem, or at least the cause.

For all devices we use a Detect() function to test for availability. The one for fmod is implemented as follows:

[code:3jaqmtnu]
PUBLIC bool cFSFmod2DSoundDevice::Detect (void)
{
FMOD::System *system ;

if (FSfmod_Initialize (system))
{
    FSfmod_Finish () ;
    return true ;
}
return (false) ;

}
[/code:3jaqmtnu]

In FSfmod_initialize() the init code I copied earlier is executed.

FSfmod_Finish looks like this:

[code:3jaqmtnu]
PUBLIC void FSfmod_Finish (void)
{
if (g_fmod_refcount > 0)
{
g_fmod_refcount– ;
if (g_fmod_refcount == 0)
{
g_fmod_system->close () ;
g_fmod_system->release () ;
g_fmod_system = NULL ;
}
}
}
[/code:3jaqmtnu]

Changing the detect function to always just return true (and not initting/finishing anything) seems to solve the problem. I just did 50 starts of our program and everyone of them ok.

There is no mismatch of Init and Finish (with and without the original Detect() ), so it seems fmod doesnt survive the start/stop/start cycle entirely.

We are starting and stopping it correctly right?

  • You must to post comments
0
0

Just to check I added the same start/stop/start cycle to the playsound example:

[code:5sv7vrlz]
/*===============================================================================================
PlaySound Example
Copyright (c), Firelight Technologies Pty, Ltd 2004-2005.

This example shows how to simply load and play multiple sounds. This is about the simplest
use of FMOD.
This makes FMOD decode the into memory when it loads. If the sounds are big and possibly take
up a lot of ram, then it would be better to use the FMOD_CREATESTREAM flag so that it is
streamed in realtime as it plays.
===============================================================================================*/

include "../../api/inc/fmod.hpp"

include "../../api/inc/fmod_errors.h"

include "../common/wincompat.h"

include <stdio.h>

void ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
exit(-1);
}
}
int main(int argc, char *argv[])
{
FMOD::System *system;
FMOD::Sound *sound1, *sound2, *sound3;
FMOD::Channel *channel = 0;
FMOD_RESULT result;
int key;
unsigned int version;

/*
    Create a System object and initialize.
*/
result = FMOD::System_Create(&amp;system);
ERRCHECK(result);

result = system-&gt;getVersion(&amp;version);
ERRCHECK(result);

if (version &lt; FMOD_VERSION)
{
    printf(&quot;Error!  You are using an old version of FMOD %08x.  This program requires %08x\n&quot;, version, F
    getch();
    return 0;
}

result = system-&gt;setOutput(FMOD_OUTPUTTYPE_ALSA);
ERRCHECK(result);

result = system-&gt;init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);

result = system-&gt;close();
ERRCHECK(result);
result = system-&gt;release();
ERRCHECK(result);

system = NULL ;

result = FMOD::System_Create(&amp;system);
ERRCHECK(result);

result = system-&gt;getVersion(&amp;version);
ERRCHECK(result);

if (version &lt; FMOD_VERSION)
{
    printf(&quot;Error!  You are using an old version of FMOD %08x.  This program requires %08x\n&quot;, version, F
    getch();
    return 0;
}

result = system-&gt;setOutput(FMOD_OUTPUTTYPE_ALSA);
ERRCHECK(result);

result = system-&gt;init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);





result = system-&gt;createSound(&quot;../media/drumloop.wav&quot;, FMOD_SOFTWARE, 0, &amp;sound1);
ERRCHECK(result);
result = sound1-&gt;setMode(FMOD_LOOP_OFF);
ERRCHECK(result);

result = system-&gt;createSound(&quot;../media/jaguar.wav&quot;, FMOD_SOFTWARE, 0, &amp;sound2);
ERRCHECK(result);

result = system-&gt;createSound(&quot;../media/swish.wav&quot;, FMOD_SOFTWARE, 0, &amp;sound3);
ERRCHECK(result);

printf(&quot;===================================================================\n&quot;);
printf(&quot;PlaySound Example.  Copyright (c) Firelight Technologies 2004-2005.\n&quot;);
printf(&quot;===================================================================\n&quot;);
printf(&quot;\n&quot;);
printf(&quot;Press '1' to Play a mono sound using software mixing\n&quot;);
printf(&quot;Press '2' to Play a mono sound using software mixing\n&quot;);
printf(&quot;Press '3' to Play a stereo sound using software mixing\n&quot;);
printf(&quot;Press 'Esc' to quit\n&quot;);
printf(&quot;\n&quot;);

/*
    Main loop.
*/
do
{
    if (kbhit())
    {
        key = getch();

        switch (key)
        {
            case '1' :
            {
                result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound1, 0, &amp;channel);
                ERRCHECK(result);
                break;
            }
            case '2' :
            {
                result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound2, 0, &amp;channel);
                ERRCHECK(result);
                break;
            }
            case '3' :
            {
                result = system-&gt;playSound(FMOD_CHANNEL_FREE, sound3, 0, &amp;channel);
                ERRCHECK(result);
                break;
            }
        }
    }

    system-&gt;update();

    {
        unsigned int ms = 0;
        unsigned int lenms = 0;
        bool         playing = 0;
        bool         paused = 0;
        int          channelsplaying = 0;

        if (channel)
        {
            FMOD::Sound *currentsound = 0;

            result = channel-&gt;isPlaying(&amp;playing);
            if ((result != FMOD_OK) &amp;&amp; (result != FMOD_ERR_INVALID_HANDLE) &amp;&amp; (result != FMOD_ERR_CHANNEL
            {
                ERRCHECK(result);
            }

            result = channel-&gt;getPaused(&amp;paused);
            if ((result != FMOD_OK) &amp;&amp; (result != FMOD_ERR_INVALID_HANDLE) &amp;&amp; (result != FMOD_ERR_CHANNEL
            {
                ERRCHECK(result);
            }

            result = channel-&gt;getPosition(&amp;ms, FMOD_TIMEUNIT_MS);
            if ((result != FMOD_OK) &amp;&amp; (result != FMOD_ERR_INVALID_HANDLE) &amp;&amp; (result != FMOD_ERR_CHANNEL
            {
                ERRCHECK(result);
            }

            channel-&gt;getCurrentSound(&amp;currentsound);
            if (currentsound)
            {
                result = currentsound-&gt;getLength(&amp;lenms, FMOD_TIMEUNIT_MS);
                if ((result != FMOD_OK) &amp;&amp; (result != FMOD_ERR_INVALID_HANDLE) &amp;&amp; (result != FMOD_ERR_CHA
                {
                    ERRCHECK(result);
                }
            }
        }

        system-&gt;getChannelsPlaying(&amp;channelsplaying);

        printf(&quot;Time %02d:%02d:%02d/%02d:%02d:%02d : %s : Channels Playing %2d\r&quot;, ms / 1000 / 60, ms / 1
        fflush(stdout);
    }

    Sleep(10);

} while (key != 27);

printf(&quot;\n&quot;);

/*
    Shut down
*/
result = sound1-&gt;release();
ERRCHECK(result);
result = sound2-&gt;release();
ERRCHECK(result);
result = sound3-&gt;release();
ERRCHECK(result);
result = system-&gt;close();
ERRCHECK(result);
result = system-&gt;release();
ERRCHECK(result);

return 0;

}

[/code:5sv7vrlz]

this crashes with the same stack trace:

(gdb) bt

0 0x08099935 in ?? ()

1 0x40096da3 in FMOD::Thread::callback () from ../../api/lib/libfmodex.so

2 0x40096d88 in FMOD::Thread::callback () from ../../api/lib/libfmodex.so

3 0x402c17f3 in start_thread () from /lib/tls/libpthread.so.0

4 0x4038562a in clone () from /lib/tls/libc.so.6

(gdb) quit

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.