DirectSound delete sound function

Started by
11 comments, last by Buckeye 15 years, 11 months ago
if (sound_nameofsound != NULL) delete sound_nameofsound; is causing a "program must close" "send error report" thing when I escape the program. anyone know a better way to clear directx sounds from system memory, or does it auto-clear?
Advertisement
What type is "sound_nameofsound"? If it's a COM interface pointer (all of the objects you use with DSound are COM objects), then you can't just delete it. The lifetime of a COM object is maintained by calling AddRef and Release, which increment or decrement the object's internal reference count. The typical way for something to say "I'm done with this interface" is to call Release on it, that way when everyone is done the object deletes itself.

If you're not familiar with any of this, you should have a look at the COM Overview found in the DX SDK.
is sound_nameofsound a direct sound buffer?

if it is, you should be calling ->Release() on it rather than using delete.

my knowledge of direct sound is pretty much non existant so if i'm wrong.. I dunno! :)
I tried the release function, and the sound name is "sound_nameofsound".

Release would be
//...
if (sound_nameofsound != NULL)
sound_nameofsound->Release();
//...
and that was generating a compiling error.
Quote:Original post by pbjgame
I tried the release function, and the sound name is "sound_nameofsound".

Release would be
//...
if (sound_nameofsound != NULL)
sound_nameofsound->Release();
//...
and that was generating a compiling error.
Telling us what the compile error was would be helpful...

And again, what is the type of sound_nameofsound? Can we see it's declaration?
CSound *sound_bounce; //variable declaration.
//...
sound_bounce = LoadSound("bounce.wav"); //loadsound function
if (sound_bounce == NULL)
return 0;
//...
if (sound_bounce != NULL)
sound_bounce->Release();
//...

260 C:\...\My Projects\dxaudio\game.cpp 'class CSound' has no member named 'Release'

and when I use
if (sound_bounce != NULL)
delete sound_bounce;
it gives me one of those "send message" "don't send message" error boxes, and when I use no delete function it seems to work just fine.
Okay CSound is not a DirectSound-created object. Is it a class you created? Is it part of some library you're using?

More importantly, did you create this object yourself using "new"?
Possibly the CSound class from the DX SDK?

class CSound{protected:    LPDIRECTSOUNDBUFFER* m_apDSBuffer;    DWORD                m_dwDSBufferSize;    CWaveFile*           m_pWaveFile;    DWORD                m_dwNumBuffers;    DWORD                m_dwCreationFlags;    HRESULT RestoreBuffer( LPDIRECTSOUNDBUFFER pDSB, BOOL* pbWasRestored );public:    CSound( LPDIRECTSOUNDBUFFER* apDSBuffer, DWORD dwDSBufferSize, DWORD dwNumBuffers, CWaveFile* pWaveFile, DWORD dwCreationFlags );    virtual ~CSound();    HRESULT Get3DBufferInterface( DWORD dwIndex, LPDIRECTSOUND3DBUFFER* ppDS3DBuffer );    HRESULT FillBufferWithSound( LPDIRECTSOUNDBUFFER pDSB, BOOL bRepeatWavIfBufferLarger );    LPDIRECTSOUNDBUFFER GetFreeBuffer();    LPDIRECTSOUNDBUFFER GetBuffer( DWORD dwIndex );    HRESULT Play( DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lVolume = 0, LONG lFrequency = -1, LONG lPan = 0 );    HRESULT Play3D( LPDS3DBUFFER p3DBuffer, DWORD dwPriority = 0, DWORD dwFlags = 0, LONG lFrequency = 0 );    HRESULT Stop();    HRESULT Reset();    BOOL    IsSoundPlaying();};
oui, monsieur lemon head.

any idea how to delete the sound on game_end? or is it automatic?
Quote:Original post by pbjgame
oui, monsieur lemon head.

any idea how to delete the sound on game_end? or is it automatic?
It depends how you created it.

Run your app in the debugger, running it like you are is like writing source code and never compiling it and then sending it off as your game - you have absolutely no idea it it'll work as expected.
There's a reason that companies spend a crapload of money to develop debuggers, they're the single most useful tool you can ever use when programming.

This topic is closed to new replies.

Advertisement