0
0

i am getting acess violation exception when i am trying to use
FSOUND_Sample_Free .

any suggestion why

the handle is a valid pointer.

  • You must to post comments
0
0

i dont think so because it is in the destructor

if(hSound!=NULL)
{
FSOUND_Sample_Free(hSound);
hSound = NULL;
channel = -1
}

it is only doing it if 2 sound samples are playing togther and i am trying to free them both (after the have stoped playing), i think that this is the problem because in other occasions it works perfectly.

  • You must to post comments
0
0

i can put the code here… but i dont think i can reproduce it becuase it is a part of a big app

SoundEffect.h

[code:184ksd4b]

ifndef _SOUNDEFFECT_H

define _SOUNDEFFECT_H

include "sound.h"

class SoundEffect :
public Sound
{
public:
SoundEffect(void);
~SoundEffect(void);

/*This method will load a new sound effect to be played it will not 
  play the sound effect but only load it.

  Parameters:filename - The file name of the sound effect to be loaded
  Return Value:none
*/
void load(string &filename);
/*This method will play the sound effect if the loop is set to true it will
  play the sound effect in endless loop

  Parameters: loop - Indication if the playback should be in endless loop
  Return Value:none
*/
void play(bool loop);
/*This method will stop the playback of the music

  Parameters:none
  Return Value:none
*/
void stop(void);
/*This method will pause or unpause the current played sound effect 
  according to the current status of the sound effect.

  Parameters:none
  Return Value: none
*/
void pause(void);
/*This method will set the volume of the music, The method will not take affect if no music
  has been loaded

  Parameters: percent - The percent of the volume from 0-1 
  Return Value: none
*/
void setVolume(double percent);
/*This method will return indication if the current sound effect is playing

  Parameters:none
  Return Value: true   - If the sound effect is currently playing
                flase  - Otherwise.
*/
bool isPlaying(void);

protected:
FSOUND_SAMPLE *hSoundEffect; //Holds the handle to the sound effect
int channel; //Holds the channel of the sound effect

void freeSoundEffect(void);

};

inline void SoundEffect::freeSoundEffect(void)
{
if(hSoundEffect!=NULL)
{
FSOUND_Sample_Free(hSoundEffect);
hSoundEffect = NULL;
channel = -1;
}
}

endif

[/code:184ksd4b]

SoundEffect.cpp

[code:184ksd4b]

SoundEffect::SoundEffect(void):Sound()
{
hSoundEffect = NULL;
channel = -1;
}

SoundEffect::~SoundEffect(void)
{
freeSoundEffect();
}

void SoundEffect::load(string &filename)
{
freeSoundEffect();
hSoundEffect = FSOUND_Sample_Load(FSOUND_FREE,filename.data(),0,0,0);
if(hSoundEffect==NULL)
{
throw Exception("Could not open sound effect file");
}
}

void SoundEffect::play(bool loop)
{
if(hSoundEffect==NULL)
{
return;
}
channel = FSOUND_PlaySound(FSOUND_FREE,hSoundEffect);
FSOUND_Sample_SetMode(hSoundEffect,FSOUND_LOOP_NORMAL);
}

void SoundEffect::stop(void)
{
if((hSoundEffect==NULL)||(channel==-1))
{
return;
}
FSOUND_StopSound(channel);
}

void SoundEffect::pause(void)
{
if((hSoundEffect==NULL)||(channel==-1))
{
return;
}
FSOUND_SetPaused(channel,!FSOUND_GetPaused(channel));
}

void SoundEffect::setVolume(double percent)
{
unsigned char vol;

vol = unsigned char (percent*255);

if((hSoundEffect==NULL)||(channel==-1))
{
    return;
}
FSOUND_SetVolume(channel,vol);

}

bool SoundEffect::isPlaying(void)
{
char result;
if((hSoundEffect==NULL)||(channel==-1))
{
return false;
}
result = FSOUND_IsPlaying(channel);
return result==1;
}
[/code:184ksd4b]

now these are the 2 functions that i am using the sound

[code:184ksd4b]

    sEffects.push_back(SoundEffect());
    sEffects.at(sEffects.size()-1).load(property.getValue()+string("\\")+filename);
    sEffects.at(sEffects.size()-1).play(false);

[/code:184ksd4b]

[code:184ksd4b]
void Application::releaseNotPlayingSounds(void)
{
static bool sEffectLastState = false; //Holds the last state of blocking sound to track change
vector<SoundEffect>::iterator itr; //Holds iterator to the sound effects vector

itr = sEffects.begin();
while(itr!=sEffects.end())
{
    if(!itr-&gt;isPlaying())
    {
        itr = sEffects.erase(itr);
    }
    else
    {
        itr++;
    }
}
//if there was a change in the play status from playing to not playing
if((!blockSEffect.isPlaying())&amp;&amp;(sEffectLastState))
{
    world.forceNextEvent();
}
sEffectLastState = blockSEffect.isPlaying();

}
[/code:184ksd4b]

i know that normally it shouldnt be a problem because it uses diffrent channels but playing is a O.K when i try to release the pointer if i playin them both the first one is ok but the second one it throws ACCESS VIOLATION

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.