0
0

I’m using fmod 4.04.18 on linux for a 24/7 project and encountered an infinite loop issue several times. It is very difficult to reproduce, the infinite loop just happens from time to time requiring a restart of the application. I just got it again and did an strace on the fmod thread that was consuming 100% cpu and got the following:
[code:1zvpfoud]gettimeofday({1154409726, 997485}, NULL) = 0
gettimeofday({1154409726, 998830}, NULL) = 0
gettimeofday({1154409726, 998929}, NULL) = 0
gettimeofday({1154409727, 272}, NULL) = 0
gettimeofday({1154409727, 375}, NULL) = 0
gettimeofday({1154409727, 1723}, NULL) = 0
gettimeofday({1154409727, 1823}, NULL) = 0
gettimeofday({1154409727, 3168}, NULL) = 0
gettimeofday({1154409727, 3269}, NULL) = 0
gettimeofday({1154409727, 4611}, NULL) = 0
gettimeofday({1154409727, 4711}, NULL) = 0
gettimeofday({1154409727, 7278}, NULL) = 0
gettimeofday({1154409727, 7396}, NULL) = 0
gettimeofday({1154409727, 8914}, NULL) = 0
gettimeofday({1154409727, 9015}, NULL) = 0
gettimeofday({1154409727, 10367}, NULL) = 0
gettimeofday({1154409727, 10465}, NULL) = 0[/code:1zvpfoud]
This keeps coming, so somehow fmod is in a infinite loop calling gettimeofday :(

What other kind of debug information should I send?

  • You must to post comments
0
0

You have to give more information than that, ie what you’re actually doing.
gettimeofday is just used in polling threads, so i think you might be onto a red herring there, that just means fmod’s threads are running?

  • You must to post comments
0
0

The following is my code:
[code:1tetbhoe]#include "PlaySound.h"

include "fmod_errors.h"

using namespace std;

std::auto_ptr<CPlaySound> CPlaySound::m_pInstance;

void ERRCHECK(FMOD_RESULT result, const char* pszURL = NULL)
{
if (result != FMOD_OK)
{
if (pszURL)
LOG_ERROR("FMOD error " << result << ": " << FMOD_ErrorString(result) << "(" << pszURL << ")");
else
LOG_ERROR("FMOD error " << result << ": " << FMOD_ErrorString(result));
}
}

CPlaySound::CPlaySound() : m_pSystem(NULL)
{
for (int i=0; i<m_siMaxNumSounds; ++i)
{
m_sounds[i].m_pSound = NULL;
m_sounds[i].m_pChannel = NULL;
m_sounds[i].m_tStartTime = 0;
}

    cout &lt;&lt; &quot;FMOD: FMOD init start...&quot; &lt;&lt; endl;

    FMOD_RESULT result = FMOD::System_Create(&amp;m_pSystem);
    ERRCHECK(result);
    if (!m_pSystem)
            return;

    unsigned int version;
    result = m_pSystem-&gt;getVersion(&amp;version);
    ERRCHECK(result);

    if (version &lt; FMOD_VERSION)
    {
            Cleanup();
            LOG_ERROR(&quot;FMOD Error! You are using an old version of FMOD &quot; &lt;&lt; version &lt;&lt; &quot;. This program requires &quot; &lt;&lt; FMOD_VERSION &lt;&lt; &quot;.&quot;);
            return;
    }

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

    result = m_pSystem-&gt;setSpeakerMode(FMOD_SPEAKERMODE_5POINT1);
    ERRCHECK(result);

    result = m_pSystem-&gt;init(m_siMaxNumSounds, FMOD_INIT_NORMAL, 0);
    ERRCHECK(result);
    cout &lt;&lt; &quot;FMOD: FMOD init done.&quot; &lt;&lt; endl;

}

CPlaySound::~CPlaySound()
{
Cleanup();
}

void CPlaySound::CleanupSound(int iIndex)
{
if (iIndex < 0 || iIndex >= m_siMaxNumSounds)
return;
cout << "FMOD: CleanupSound(" << iIndex << ")" << endl;
if (m_sounds[iIndex].m_pSound)
{
FMOD_RESULT result = m_sounds[iIndex].m_pSound->release();
ERRCHECK(result);
m_sounds[iIndex].m_pSound = NULL;
m_sounds[iIndex].m_pChannel = NULL;
m_sounds[iIndex].m_tStartTime = 0;
}
}

void CPlaySound::Cleanup()
{
for (int i=0; i<m_siMaxNumSounds; ++i)
CleanupSound(i);

    if (m_pSystem)
    {
            FMOD_RESULT result = m_pSystem-&gt;close();
            ERRCHECK(result);
            result = m_pSystem-&gt;release();
            ERRCHECK(result);
            m_pSystem = NULL;
    }

}

int CPlaySound::GetFreeSoundSlot()
{
int iIndexOldest = 0;
for (int i=0; i<m_siMaxNumSounds; ++i)
{
if (m_sounds[i].m_pSound == NULL)
return i;
if (m_sounds[i].m_tStartTime < m_sounds[iIndexOldest].m_tStartTime)
iIndexOldest = i;
}
// No free sound slot, free the oldest slot.
CleanupSound(iIndexOldest);
return iIndexOldest;
}

void CPlaySound::PlayStream(const char* pszFilename)
{
if (!pszFilename || !m_pSystem)
return;

    int iFreeSlot = GetFreeSoundSlot();
    cout &lt;&lt; &quot;FMOD: GetFreeSoundSlot() = &quot; &lt;&lt; iFreeSlot &lt;&lt; endl;
    FMOD_RESULT result = m_pSystem-&gt;createSound(pszFilename, FMOD_HARDWARE | FMOD_2D | FMOD_CREATESTREAM, 0, &amp;(m_sounds[iFreeSlot].m_pSound));
ERRCHECK(result, pszFilename);
    if (m_sounds[iFreeSlot].m_pSound)
    {
            result = m_pSystem-&gt;playSound(FMOD_CHANNEL_FREE, m_sounds[iFreeSlot].m_pSound, true, &amp;(m_sounds[iFreeSlot].m_pChannel));
            ERRCHECK(result, pszFilename);
            if (m_sounds[iFreeSlot].m_pChannel)
            {
                    result = m_sounds[iFreeSlot].m_pChannel-&gt;setSpeakerMix(0, 0, 0, 0, 1.0f, 1.0f, 0, 0);
                    ERRCHECK(result);
                    result = m_sounds[iFreeSlot].m_pChannel-&gt;setPaused(false);
                    ERRCHECK(result);
                    m_sounds[iFreeSlot].m_tStartTime = time(NULL);
            }
    }

}[/code:1tetbhoe]

Note: The strace was of a thread that was indeed polling with gettimeofday, however, it was polling constantly using 100% CPU.

What other information can I send to you?

  • You must to post comments
0
0

is your main thread sleeping at all or yielding control of the task system enough to let fmod process its threads?
Also, try a different output mode (ie OSS) and stereo instead of 5.1 and let me know what happens.

  • You must to post comments
0
0

Yes, the main thread and other non-fmod threads sleep around 50% of the time.
It’s difficult to switch to stereo or OSS, because then the system isn’t working anymore like it should and it’s an operational system.
Will a stacktrace be usefull?

  • You must to post comments
0
0

I did some more experimenting.
As a test, I started another program in the background (not sound related) that uses 100% CPU. When this background program is closed after several minutes, chances are very high that FMOD in my program starts to consume 100% CPU.
I also did a new strace when FMOD was hogging the CPU and got the following results:
[b:s3zahwnx]NOTE:[/b:s3zahwnx] In my full strace logs I can see that gettimeofday is called approximately 1200 times per second.[code:s3zahwnx]19:50:51 gettimeofday({1154800251, 987740}, NULL) = 0
19:50:51 gettimeofday({1154800251, 989158}, NULL) = 0
19:50:51 gettimeofday({1154800251, 989272}, NULL) = 0
19:50:51 gettimeofday({1154800251, 990810}, NULL) = 0
19:50:51 gettimeofday({1154800251, 990926}, NULL) = 0
19:50:51 gettimeofday({1154800251, 992395}, NULL) = 0
19:50:51 gettimeofday({1154800251, 992510}, NULL) = 0
19:50:51 gettimeofday({1154800251, 993930}, NULL) = 0
19:50:51 gettimeofday({1154800251, 994046}, NULL) = 0
19:50:51 gettimeofday({1154800251, 995463}, NULL) = 0
19:50:51 gettimeofday({1154800251, 995577}, NULL) = 0
19:50:51 gettimeofday({1154800251, 996994}, NULL) = 0
19:50:51 gettimeofday({1154800251, 997108}, NULL) = 0
19:50:51 gettimeofday({1154800251, 998525}, NULL) = 0
19:50:51 gettimeofday({1154800251, 998641}, NULL) = 0
19:50:51 gettimeofday({1154800252, 42}, NULL) = 0
19:50:52 gettimeofday({1154800252, 157}, NULL) = 0
19:50:52 gettimeofday({1154800252, 3354}, NULL) = 0
19:50:52 gettimeofday({1154800252, 3488}, NULL) = 0
19:50:52 gettimeofday({1154800252, 4970}, NULL) = 0
19:50:52 gettimeofday({1154800252, 5085}, NULL) = 0
19:50:52 gettimeofday({1154800252, 6505}, NULL) = 0
19:50:52 gettimeofday({1154800252, 6621}, NULL) = 0
19:50:52 gettimeofday({1154800252, 8035}, NULL) = 0
19:50:52 gettimeofday({1154800252, 8150}, NULL) = 0
19:50:52 gettimeofday({1154800252, 9567}, NULL) = 0
19:50:52 gettimeofday({1154800252, 9683}, NULL) = 0
19:50:52 gettimeofday({1154800252, 11247}, NULL) = 0
19:50:52 gettimeofday({1154800252, 11365}, NULL) = 0[/code:s3zahwnx]

  • You must to post comments
0
0

Is there any other information that I can give to try to fix this?

  • You must to post comments
Showing 6 results
Your Answer

Please first to submit.