Jump to content
  • Advertisement
Sign in to follow this  
pbjgame

DirectSound delete sound function

This topic is 3817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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! :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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"?

Share this post


Link to post
Share on other sites
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();
};

Share this post


Link to post
Share on other sites
oui, monsieur lemon head.

any idea how to delete the sound on game_end? or is it automatic?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!