idanbeck at January 2nd, 2009 03:34 — #1
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!
kenneth_gorking at January 2nd, 2009 17:03 — #2
I doubt an unreleased object would hang the app, it would just leak memory. Something else must be preventing the app from exiting.
idanbeck at January 2nd, 2009 17:08 — #3
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!
kenneth_gorking at January 2nd, 2009 18:02 — #4
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?
idanbeck at January 3rd, 2009 21:48 — #5
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.
kenneth_gorking at January 4th, 2009 06:28 — #6
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.