Jump to content


DirectSound creation/deletion preventing application from closing?


5 replies to this topic

#1 idanbeck

    New Member

  • Members
  • Pip
  • 3 posts

Posted 02 January 2009 - 08:34 AM

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,

                                &m_pDSound,

                                NULL

                           );

    CHRM(hr, "DirectSoundCreate8");


    //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


    if(m_pDSoundBuffer)

    {

        m_pDSoundBuffer->Stop();

        m_pDSoundBuffer->Release();

        m_pDSoundBuffer = NULL;

    }


    if(m_pDSound)

    {        

        m_pDSound->Release();

        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!
djb

#2 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 02 January 2009 - 10:03 PM

I doubt an unreleased object would hang the app, it would just leak memory. Something else must be preventing the app from exiting.
"Stupid bug! You go squish now!!" - Homer Simpson

#3 idanbeck

    New Member

  • Members
  • Pip
  • 3 posts

Posted 02 January 2009 - 10:08 PM

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!

#4 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 02 January 2009 - 11:02 PM

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?
"Stupid bug! You go squish now!!" - Homer Simpson

#5 idanbeck

    New Member

  • Members
  • Pip
  • 3 posts

Posted 04 January 2009 - 02:48 AM

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.

#6 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 04 January 2009 - 11:28 AM

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.
"Stupid bug! You go squish now!!" - Homer Simpson





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users