Thread: COM object problems

  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    COM object problems

    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.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The line in question is the commented line in the CDXSoundSegment destructor.
    Also segment state needs to be released and it works fine when I attempt to release it - but not for the sound segment. Very odd.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 01-23-2008, 06:21 AM
  2. Finding object code
    By kidburla in forum C Programming
    Replies: 3
    Last Post: 11-29-2005, 01:09 PM
  3. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  4. Class Problems
    By Dae in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2005, 04:40 PM