Reputation: 3
when i call the function of "DirectSoundCreate" to get "IDirectSound" pointer, but i couldn't release it when exit the process at the destructor. Like this:
IDirectSound* m_pDirectSound;
IDirectSoundBuffer* m_pDsSoundBuffer;
HRESULT hResult = DirectSoundCreate(NULL, &m_pDirectSound,NULL );
hResult =
m_pDirectSound->SetCooperativeLevel
(hWnd,DSSCL_NORMAL|DSSCL_EXCLUSIVE|DSSCL_PRIORITY);
here release:
if(m_pDirectSound)
{
m_pDirectSound->Release();
}
the program will block at here forever!
so anyone can help me? shall i release the pointer m_pDirectSound
? thanks a lot!
Upvotes: 0
Views: 678
Reputation: 596672
Make sure you are not calling CoUninitialize()
too soon. If there are still COM objects active when COM is unloaded, calling Release()
afterwards can exhibit all kinds of undefined behavior, including crashes and deadlocks.
Upvotes: 1
Reputation: 1366
sometimes memory leaks may cause such situation. you should check your program whether there is any memory problem.
Your code is not safe.
IDirectSound* m_pDirectSound = NULL;
IDirectSoundBuffer* m_pDsSoundBuffer = NULL;
HRESULT hResult = DirectSoundCreate(NULL, &m_pDirectSound,NULL );
hResult =
m_pDirectSound->SetCooperativeLevel
(hWnd,DSSCL_NORMAL|DSSCL_EXCLUSIVE|DSSCL_PRIORITY);
if(FAILED(hResult)) return ;
//if not at the constructor you should type 'return hResult'
you can visit&download example from this website . http://www.rastertek.com/dx11tut14.html
I learn dx11 from it.
:)
Upvotes: 2