0
0

I am using the latest version of fmod to play sounds in a project i am developing. However, a minute and a half after the game starts, i get a Heap Corruption enabled breakpoint by Visual Studio 2008 Express Edition, with an error regarding memory having been modified after freed. I’ve checked the source and no error appear, so i commented out everything associated with fmod and the bug disappears. Is this a know issue? am i doing something wrong? i’ll paste the class i wrote.
Thank you for your help.
[code:1ewm1j9b]

include <FMOD/fmod.hpp>

include <FMOD/fmod_errors.h>

include <stdio.h>

class Multimedia
{
public:
Multimedia();
~Multimedia();
//reproduce el sonido de fondo para el juego//
void reproducir_sonido(Mmedia indice_sonido);
void cargar_sonido(void);
void reproducir_sonido_disparo(void);
void reproducir_musica_fondo(Mmedia indice_sonido);
void set_habilitacion_sonidos(bool hab){this->habilitacion = hab;};
//***//

private:
char* get_sonido(int sonido);
bool habilitacion;
///*****FMOD****//
FMOD::System *system;
FMOD::Sound** sonido;
FMOD::Channel *channel;
FMOD::Channel *channel_fondo;
FMOD_RESULT result;
int key;
unsigned int version;
Mmedia reproduciendo;
void ERRCHECK(FMOD_RESULT result);
//*****************//
};

Multimedia::~Multimedia()
{

for(Mmedia i = 0; i &lt; MULTIMEDIA_MOD;i++)
{
    result = sonido[i]-&gt;release();
    ERRCHECK(result);
}
delete []sonido;

}

Multimedia::Multimedia()
{
////////////********FMOD*********/////////
habilitacion = true;
//reservamos memoria para los diferentes sonidos//
reproduciendo = 0;
sonido = new FMOD::Sound*[MULTIMEDIA_MOD];
assert(sonido);
channel = 0;
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
exit(0);
}
result = system->init(32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
cargar_sonido();
///////*************/////////////////
}
void Multimedia::reproducir_sonido_disparo(void)
{
int sonido;
sonido = (rand() % 7) + 20;
//this->reproducir_sonido(sonido);
return;
}
void Multimedia::cargar_sonido(void)
{
for(Mmedia i = 10 ; i < MULTIMEDIA_MOD + 10; i++)
{
cout << "this->get_sonido(i)"<<this->get_sonido(i)<<endl;
result = system->createSound(this->get_sonido(i),
FMOD_HARDWARE, 0, &sonido[i]);
ERRCHECK(result);
cout << "Sonido["<<i<<"] cargado"<<endl;
}
}
void Multimedia::reproducir_musica_fondo(Mmedia indice_fondo)
{
if(habilitacion)
{
system->update();
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = 0;
bool paused = 0;
int channelsplaying = 0;

        channel_fondo-&gt;isPlaying(&amp;playing);
        if(playing)
            channel_fondo-&gt;stop();
        result = system-&gt;playSound(FMOD_CHANNEL_FREE, sonido[indice_fondo], 
                                   false, &amp;channel_fondo);
        ERRCHECK(result);
        if (channel_fondo)
        {
            FMOD::Sound *currentsound = 0;
            result = channel_fondo-&gt;isPlaying(&amp;playing);
            if ((result != FMOD_OK) &amp;&amp; (result != FMOD_ERR_INVALID_HANDLE) &amp;&amp; (result != FMOD_ERR_CHANNEL_STOLEN))
            {
                ERRCHECK(result);
            }

            channel_fondo-&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_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }
            }
            cout &lt;&lt; &quot;Currentsound--&gt;&quot;&lt;&lt;currentsound&lt;&lt;endl;
        }
        system-&gt;getChannelsPlaying(&amp;channelsplaying);
     }
    Sleep(10); 
}

}

void Multimedia::reproducir_sonido(Mmedia indice_sonido)
{
if(habilitacion)
{
system->update();
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = 0;
bool paused = 0;
int channelsplaying = 0;
result = system->playSound(FMOD_CHANNEL_FREE, sonido[indice_sonido], false, &channel);
ERRCHECK(result);
if (channel)
{
FMOD::Sound *currentsound = 0;
result = channel->isPlaying(&playing);
if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))
{
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_CHANNEL_STOLEN))
                {
                    ERRCHECK(result);
                }
            }
            cout &lt;&lt; &quot;Currentsound--&gt;&quot;&lt;&lt;currentsound&lt;&lt;endl;
        }
        system-&gt;getChannelsPlaying(&amp;channelsplaying);
     }
    Sleep(10); 
}

}
char* Multimedia::get_sonido(Mmedia sonido_en_celda)
{
switch(sonido_en_celda)
{
//returns a string with the location of the sound file

}

}

void Multimedia::ERRCHECK(FMOD_RESULT result)
{
if (result != FMOD_OK)
{
printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
getchar();
exit(ERROR_FMOD);

}

}
[/code:1ewm1j9b]
the bool habilitacion simply enables of disables playback the brute force way, it sucks as code niceness, but it does it’s job.
I would appreciate all the help i cant get.

  • You must to post comments
0
0

[code:281epd9l] if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN))[/code:281epd9l]

result != FMOD_OK this is redundant since it’s inside your ERRCHECK function.

(result != FMOD_ERR_INVALID_HANDLE) && (result != FMOD_ERR_CHANNEL_STOLEN)
You should be handling these errors not ignoring them.

[code:281epd9l] for(Mmedia i = 10 ; i < MULTIMEDIA_MOD + 10; i++)
{
result = system->createSound(this->get_sonido(i),
FMOD_HARDWARE, 0, &sonido[i]); [/code:281epd9l]
I’m not quite sure why the index starts at 10 but it looks like it conflicts with this line:
[code:281epd9l]sonido = new FMOD::Sound*[MULTIMEDIA_MOD]; [/code:281epd9l]

[code:281epd9l]void Multimedia::reproducir_sonido(Mmedia indice_sonido)
{
if(habilitacion)
{
system->update();
{
unsigned int ms = 0;
unsigned int lenms = 0;
bool playing = 0;
bool paused = 0;
int channelsplaying = 0;

     // check that innice_sonido is a valid index (choose one of these)

if 1

     assert((indice_sonido &gt;= 0) &amp;&amp; (indice_sonido &lt; MULTIMEDIA_MOD));

else

     assert((indice_sonido &gt;= 10) &amp;&amp; (indice_sonido &lt; (MULTIMEDIA_MOD + 10)));

endif

     result = system-&gt;playSound(FMOD_CHANNEL_FREE, sonido[indice_sonido], false, &amp;channel);
     ERRCHECK(result);
     if (channel)
     {
        result = channel-&gt;isPlaying(&amp;playing);
        // skip if the handle is invalid
        if ((result != FMOD_ERR_INVALID_HANDLE) &amp;&amp; (result != FMOD_ERR_CHANNEL_STOLEN))
        {
           FMOD::Sound *currentsound = 0;                          

           channel-&gt;getCurrentSound(&amp;currentsound);
           ERRCHECK(result);

           if (currentsound)
           {
              result = currentsound-&gt;getLength(&amp;lenms, FMOD_TIMEUNIT_MS);
              ERRCHECK(result);
           }
           cout &lt;&lt; &quot;Currentsound--&gt;&quot;&lt;&lt;currentsound&lt;&lt;endl;
        }
     }
     system-&gt;getChannelsPlaying(&amp;channelsplaying);
   }
  Sleep(10);

}
} [/code:281epd9l]

I’m not sure if it will fix your problem. If you can see which function call is causing the heap corruption it would probably make it easier for us to find the problem.

  • You must to post comments
0
0

I’m working on a student game for my final project and I’m getting the same error. I’m using Visual Studio 2005 and I get the heap corruption on system->release() on shutdown after playing the game for about 2 minutes. The heap corruption only happens when I play a sound with FMOD_3D and FMOD_HARDWARE. if i do (FMOD_3D | FMOD_SOFTWARE) it doesn’t give me the heap corruption.

This is from a log of when the game doesn’t crash
[code:lfptecp5]FMOD: SystemI::close : Free software output.
FMOD: SystemI::close : Free emulated output.
FMOD: SystemI::close : Free channel pool.
FMOD: SystemI::close : Remove DSP Soundcard unit.
FMOD: SystemI::close : Remove miscllaneous DSP stuff.
FMOD: SystemI::close : done.[/code:lfptecp5]

This is from a log of when it does crash. It crashes before it does the miscellaneous DSP stuff.
[code:lfptecp5]FMOD: SystemI::close : Free software output.
FMOD: SystemI::close : Free emulated output.
FMOD: SystemI::close : Free channel pool.
FMOD: SystemI::close : Remove DSP Soundcard unit.
[/code:lfptecp5]

  • You must to post comments
0
0

Try upgrading your version there was a bug fix a few weeks back where the System::close function accessed some free memory.

  • You must to post comments
0
0

[quote="brett":3lbk54vm]Try upgrading your version there was a bug fix a few weeks back where the System::close function accessed some free memory.[/quote:3lbk54vm]

I’ve got version 4.20.04 stable and it still does it.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.