Code:
class CDXSoundSegment
{
protected:
bool Looping;
bool Playing;
WCHAR *Filename;
public:
IDirectMusicSegment8 *Segment;
IDirectMusicSegmentState8 *SegState;
CDXSoundSegment(void):Segment(NULL),SegState(NULL),Looping(false),Playing(false) {}
virtual ~CDXSoundSegment(void)
{
//SAFE_RELEASE(Segment);
};
void SetLooping(bool _cond)
{
Looping=_cond;
if (_cond)
{
//Segment->SetLoopPoints(0,0);
Segment->SetRepeats(DMUS_SEG_REPEAT_INFINITE);
} else Segment->SetRepeats(0);
}
bool GetLooping(void) {return Looping;};
WCHAR *GetFilename(void) {return Filename;};
};
Code:
class CDXSoundEmitter
{
protected:
std::vector<CDXSoundSegment> Sounds;
IDirectMusicLoader8 *Loader;
IDirectMusicPerformance8 *Performance;
public:
CDXSoundEmitter(void):Loader(NULL),Performance(NULL) {}
virtual ~CDXSoundEmitter(void)
{
for (std::vector<CDXSoundSegment>::iterator s_obj=Sounds.begin();
s_obj!=Sounds.end();s_obj++)
{
s_obj->Segment->Unload((IDirectMusicPerformance8 *)Performance);
}
Sounds.clear();
}
void Create(IDirectMusicLoader8 *_Loader,IDirectMusicPerformance8 *_Performance)
{
Loader=_Loader;
Performance=_Performance;
}
unsigned int LoadSound(WCHAR *Filename);
void Play(unsigned int _ID,unsigned int _mode);
HRESULT GetPlaying(unsigned int _ID)
{
return Performance->IsPlaying(Sounds[_ID].Segment,Sounds[_ID].SegState);
}
void SetLooping(unsigned int _ID,bool _cond)
{
Sounds[_ID].SetLooping(_cond);
}
void SetVolume(unsigned int _ID,float _Volume);
void Stop(unsigned int _ID)
{
Performance->StopEx((IDirectMusicSegmentState8 *)Sounds[_ID].SegState,NULL,0);
}
};
Why does the destructor for CDXSoundSegment generate a 'memory could not be read' error upon shutdown ONLY in a DEBUG session in MSVC?
The sound object should still be valid inside the destructor because it was never released. Does the vector release it when I call clear()? If so then why does C++ call the destructor if the object has already gone out of scope??
This is the only error I have right now inside the game engine and Shakti and I simply can't figure out what is going on.
It works fine if you don't release the COM object, but that's not acceptable.