So I am somewhat stumped on this subject and it is appearing in both my implementations of DirectSound and DirectInput at the moment but I am having problems releasing the direct sound object. I am running a toy example of my encapsulation at this point but I will put some of the code here since this is part of a much larger codebase.
To create the DirectSound object I use this snippet member function of the Implementation Class
// First Create the DirectSoundObject
hr = DirectSoundCreate8( NULL,
//CHRM(CoInitializeEx(NULL, 0), "CoInitializeEx");
CHRM(m_pDSound->SetCooperativeLevel(m_hwnd, DSSCL_PRIORITY), "SetCooperativeLevel");
and then when I delete the implementation class this code snippet is called
m_pDSoundBuffer = NULL;
m_pDSound = NULL;
So the way that the implementation is generated is through a factory class which then passes the implementation to an object which contains the sound data. Both implementation and data classes are abstracted but I doubt that this could somehow interfere with DirectSound. Basically what happens is that at program exit the implementatio class is deleted and this code is called but in the end the console simply hangs although it is not running any of my code. It seems like there is something else referencing the DirectSound object but I can't seem to figure out what that is. It definitely is not my code since at this point I have stripped out everything except creating and deleting the DirectSound object.
Any help would be greatly appreciated, thanks!
I doubt an unreleased object would hang the app, it would just leak memory. Something else must be preventing the app from exiting.
This is what I thought too but I verified that it has to do directly with the DirectSound object since when I comment out the function call that calls the IDirectSoundCreate8 sequence below and keep m_pDSound NULL then no hang occurs. One possibility, I've just realized, is that when I acquire the HWND of the window I give the console window a new title and then retrieve the handle through this title. Would changing the title like that mess something up or perhaps I need to release the handle to the window as well?
Thanks for the reply!
Hard to say, it has been a while since I have messed around with consoles
What does the DirectX debug output say when you run your program?
Its not giving me much info. I have attempted to use FreeConsole() and this will actually kill the console but the process itself doesn't seem to close. I mean is there anything that I need to do with the DirectSound object to have it close correctly?
This is quite perplexing to me. I've ensured that not only are the DirectX objects being released correctly the other data is as well. I don't see why this would prevent the application from closing, however, since it should just result in a leak.
Can you put together a small codesample that reproduce the hang, and post it here? I will try and run it, to see if it also happens on my machine.