Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm using CreateDXGIFactory to get the graphics adapters and display modes. When I call it, it works fine and I get all the data. However, when I exit my program, the main Win32 thread exits, but something stays open because it keeps debugging. Does CreateDXGIFactory create an extra thread and I'm not closing it? I don't understand. The only thing I would suspect is that in the documentation it says it doesn't work if it's called from DllMain. It is in a DLL, but it's not called from DllMain. And it doesn't fail, either.

I'm using DirectX 11.

Here is the function that initializes DirectX. I haven't gotten past retrieving the refresh rate because of this problem. I commented everything out to pinpoint the problem.

bool CGraphicsManager::InitDirectX(HWND hWnd, int width, int height)
    {
        HRESULT result;

        IDXGIFactory* factory;
        IDXGIOutput* output;
        IDXGIAdapter* adapter;
        DXGI_MODE_DESC* displayModes;
        DXGI_ADAPTER_DESC adapterDesc;

        unsigned int modeCount = 0;
        unsigned int refreshNum = 0;
        unsigned int refreshDen = 0;

        //First, we need to get the monitors refresh rater
        result = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
        //if(FAILED(result))
        //{
            //MemoryUtil::MessageBoxError(TEXT("InitDirectX"), 0, 0, TEXT("Failed to create DXGI factory\nError:\n%s"), DXGetErrorDescription(result));
            //return false;
        //}

        /*//Create a graphics card adapter
        result = factory->EnumAdapters(0, &adapter);
        if(FAILED(result))
        {
            MemoryUtil::MessageBoxError(TEXT("InitDirectX"), 0, 0, TEXT("Failed to get graphics adapters\nError:\n%s"), DXGetErrorDescription(result));
            return false;
        }

        //Get the output
        result = adapter->EnumOutputs(0, &output);
        if(FAILED(result))
        {
            MemoryUtil::MessageBoxError(TEXT("InitDirectX"), 0, 0, TEXT("Failed to get adapter output\nError:\n%s"), DXGetErrorDescription(result));
            return false;
        }

        //Get the modes
        result = output->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &modeCount, 0);
        if(FAILED(result))
        {
            MemoryUtil::MessageBoxError(TEXT("InitDirectX"), 0, 0, TEXT("Failed to get mode count\nError:\n%s"), DXGetErrorDescription(result));
            return false;
        }

        displayModes = new DXGI_MODE_DESC[modeCount];
        result = output->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_ENUM_MODES_INTERLACED, &modeCount, displayModes);
        if(FAILED(result))
        {
            MemoryUtil::MessageBoxError(TEXT("InitDirectX"), 0, 0, TEXT("Failed to get display modes\nError:\n%s"), DXGetErrorDescription(result));
            return false;
        }

        //Now we need to find one for our screen size
        for(unsigned int i = 0; i < modeCount; i++)
        {
            if(displayModes[i].Width == (unsigned int)width)
            {
                if(displayModes[i].Height == (unsigned int)height)
                {
                    refreshNum = displayModes[i].RefreshRate.Numerator;
                    refreshDen = displayModes[i].RefreshRate.Denominator;
                    break;
                }
            }
        }

        //Store the video card data
        result = adapter->GetDesc(&adapterDesc);
        if(FAILED(result))
        {
            MemoryUtil::MessageBoxError(TEXT("InitDirectX"), 0, 0, TEXT("Failed to get adapter description\nError:\n%s"), DXGetErrorDescription(result));
            return false;
        }
        m_videoCard = new CVideoCard();
        MemoryUtil::CreateGameObject(m_videoCard);

        m_videoCard->VideoCardMemory = (unsigned int)(adapterDesc.DedicatedVideoMemory);
        wcstombs_s(0, m_videoCard->VideoCardDescription, 128, adapterDesc.Description, 128);*/

        //ReleaseCOM(output);
        //ReleaseCOM(adapter);
        ReleaseCOM(factory);
        //DeletePointerArray(displayModes);

        return true;
    }

Also, I don't know if this means anything, but this is some of the output log when the function is commented out:

//...
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Program Files (x86)\Common Files\microsoft shared\ink\tiptsf.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll', Cannot find or open the PDB file
The program '[6560] LostRock.exe: Native' has exited with code 0 (0x0).

And when it isn't commented out...

//...
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file
'LostRock.exe': Unloaded 'C:\Windows\SysWOW64\setupapi.dll'
'LostRock.exe': Unloaded 'C:\Windows\SysWOW64\devobj.dll'
'LostRock.exe': Unloaded 'C:\Windows\SysWOW64\cfgmgr32.dll'
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
'LostRock.exe': Loaded 'C:\Windows\SysWOW64\oleacc.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0xb94) has exited with code 0 (0x0).

The program '[8096] LostRock.exe: Native' has exited with code 0 (0x0). //This is called when I click "Stop Debugging"

P.S. I know it is CreateDXGIFactory because if I comment it out, the program exits correctly.

share|improve this question
    
Just because the problem goes away when you comment out a line of code does not prove definitively that that line of code was directly responsible -- only that the change you made to the program modifies it such that the behavior no longer reproduces exactly. –  Josh Petrie Apr 1 '12 at 21:50
    
I think you're going to have to post more code; if you can comment out CreateDXGIFactory and your program still functions (without any other commenting-out), your program is probably simple enough to post here. –  Josh Petrie Apr 1 '12 at 21:51
    
Ok, I'll post the code. I was creating a program just to test my memory on how to correctly initialize DirectX. It must not be as good as I thought... –  smoth190 Apr 1 '12 at 22:04
add comment

2 Answers 2

up vote 0 down vote accepted

I figured it out. For some reason the project was set to be a console project, I must have accidentally changed it. I noticed the console window flash when I started the game, and I changed it back. Now it works.

share|improve this answer
add comment

No, DXGI doesn't do anything like that. Are you creating threads elsewhere in your program? Are you sure your thread isn't actually getting stuck on some cleanup call and hanging? Step through with a debugger if you can to see if your main thread is actually exiting, and do an audit of any places you create and release threads.

share|improve this answer
    
I create no threads in my program, and when stepping through, it goes right out through the end of WinMain, but the debugger doesn't stop. The program is still listed in the task manager. –  smoth190 Apr 1 '12 at 19:19
    
And make sure you Release() everything you are supposed to be calling Release() on. –  Josh Petrie Apr 1 '12 at 21:52
    
Yes, everything (Including the factory) is released. –  smoth190 Apr 1 '12 at 22:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.