Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:45:37+00:00 2026-06-12T00:45:37+00:00

I had a problem with my D3D11CreateDeviceAndSwapChain(). I thought I got a solution in

  • 0

I had a problem with my D3D11CreateDeviceAndSwapChain(). I thought I got a solution in a prev thread, so I already marked it as solved. [Create Swap Chain Failed

Looks like I fooled myself when I accidentally returned the HRESULT as a bool…

I been fighting this problem all day & still have not figured it out. Here are bunch of debug info about the inputs & outputs…

1] Taking the advice to use UNKNOWN with a non-null vAdapter:
Debug Pic http://content.wuala.com/contents/RandomClown/Public/RandomCrap/Debug%201.png

2] Following the DX sample by leaving it null & using type HARDWARE:
Debug Pic http://content.wuala.com/contents/RandomClown/Public/RandomCrap/Debug%202.png

The pics might be enough for someone to spot out the problem, but in case it was something else, code:

//      This is some relevant stuff [anything referenced] in the class.

Graphics(){
    selectedVAdapter=NULL;
    deviceInterface=NULL;
    deviceContext=NULL;
    swapChain=NULL;
}

bool initDevice(HWND &hWnd){
    HRESULT success=S_OK;

    D3D_FEATURE_LEVEL featureLevels[]={
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
        D3D_FEATURE_LEVEL_9_3,
    };
    uint featuresSize=ARRAYSIZE(featureLevels);

    D3D_DRIVER_TYPE driverTypes[]={
        D3D_DRIVER_TYPE_UNKNOWN, // Needed for manual vid adapter setting
        D3D_DRIVER_TYPE_HARDWARE,
        D3D_DRIVER_TYPE_WARP,
        D3D_DRIVER_TYPE_REFERENCE,
    };
    uint driversSize=ARRAYSIZE(driverTypes);

    refreshVideoAdapters();
    setVideoAdapter();

    //setSampleQuality();

    DXGI_SWAP_CHAIN_DESC sd;
    ZeroMemory(&sd, sizeof(sd));
    sd.BufferCount = settings.bufferCount;
    sd.BufferDesc.Width = settings.width;
    sd.BufferDesc.Height = settings.height;
    sd.BufferDesc.Format = settings.colorDepth;
    sd.BufferDesc.RefreshRate.Numerator = settings.rateNumerator;
    sd.BufferDesc.RefreshRate.Denominator = settings.rateDenominator;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = hWnd;
    sd.SampleDesc.Count = settings.sampleCount;
    sd.SampleDesc.Quality = settings.sampleQuality;
    sd.Windowed = !settings.fullScreen;

    uint flag=0;
    #ifdef _DEBUG
        flag|=D3D11_CREATE_DEVICE_DEBUG;
    #endif

    for(uint i=0; i<driversSize; i++){ // SwapChain: http://msdn.microsoft.com/en-us/library/ff476083%28v=vs.85%29.aspx
        D3D_DRIVER_TYPE driver=driverTypes[i];
        success=D3D11CreateDeviceAndSwapChain(
            //NULL,
            selectedVAdapter, driver, NULL, flag,
            featureLevels, featuresSize, D3D11_SDK_VERSION, &sd,
            &swapChain, &deviceInterface, &selectedFeatureLevel, &deviceContext);
        if(SUCCEEDED(success)) break;
    }

    return SUCCEEDED(success);
}

//      Methods to manage video adapters
void refreshVideoAdapters(){
    IDXGIAdapter1* pAdapter;
    IDXGIFactory1* pFactory=NULL;

    uint lastID=0;
    if(selectedVAdapter){
        DXGI_ADAPTER_DESC1* desc=NULL;
        selectedVAdapter->GetDesc1(desc);
        lastID=desc->DeviceId;
        releaseVideoAdapters();
    }

    if(FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory))) return;

    for(uint i=0; pFactory->EnumAdapters1(i, &pAdapter)!=DXGI_ERROR_NOT_FOUND; i++){
        vAdapters.push_back(pAdapter);

        if(lastID){
            DXGI_ADAPTER_DESC1* desc=NULL;
            pAdapter->GetDesc1(desc);
            if(lastID==desc->DeviceId){
                selectedVAdapter=pAdapter;
                lastID=0;
            }
        }
    }

    if(pFactory) pFactory->Release();
}
void releaseVideoAdapters(){
    for(uint i=0; i<vAdapters.size(); i++){
        vAdapters[i]->Release();
        vAdapters[i]=NULL;
    }
    vAdapters.clear();
    selectedVAdapter=NULL;
}
IDXGIAdapter1* getVideoAdapter(){return selectedVAdapter;}
bool setVideoAdapter(uint num=0){
    if(num<vAdapters.size()){
        selectedVAdapter=vAdapters[num];
        return 1;
    }
    return 0;
}

// Member vars
private:
SettingsGraphicsDevice settings;

D3D_FEATURE_LEVEL selectedFeatureLevel;

vector<IDXGIAdapter1*> vAdapters;
IDXGIAdapter1* selectedVAdapter;

ID3D11Device* deviceInterface;
ID3D11DeviceContext* deviceContext;
IDXGISwapChain* swapChain;

Settings struct from that code:

struct SettingsGraphicsDevice{
    uint width, height;
    bool fullScreen, vsync;
    uint rateNumerator;
    uint rateDenominator;
    uint bufferCount;
    uint sampleCount, sampleQuality;
    DXGI_FORMAT colorDepth;
    float minDist, maxDist;

    SettingsGraphicsDevice(){
        width=height=0;
        fullScreen=0;
        vsync=0;

        rateNumerator=0;
        rateDenominator=1;
        bufferCount=1;
        sampleCount=1, sampleQuality=0;
        colorDepth=DXGI_FORMAT_R8G8B8A8_UINT;

        minDist=0.1f;
        maxDist=1000.0f;
    }

};

Thanks for reading. Hope a solution is found this time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:45:39+00:00Added an answer on June 12, 2026 at 12:45 am

    Copy and Paste from my comment: “Also, a quick peek at my code shows that I use DXGI_FORMAT_R8G8B8A8_UNORM, although I currently have no clue whether that’s the correct mode.”. Ok, so it’s in an answer now 🙂

    Yeah, the formats… the DXGI_FORMAT is a rather large enumeration, but in many situations only certain formats are allowed. It shouldn’t be too surprising that only certain formats are allowed for displaying, whether it’s fullscreen or not.

    I got the value that I used from the docs (as usual), specifically the list in the DXGI_MODE_DESC description. I don’t actually know whether I’m creating a blt-block transfer swapchain, but decided that these values are as good as any to start with, and even though I don’t care about feature level 9 it seemed pretty safe 🙂

    I have no idea why your code seemed to work wit a null-adapter; I think that’s confusing. Maybe the debug runtime would have caught it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a problem that I posted before but got no clear solution How
_ I had problem with installing the mod_wsgi.I have found the solution as below
I had a problem this week (which thankfully I've solved in a much better
I had a problem in xml's parsing. I got two xml files.... example xml
** SOLVED * PROBLEM HAD TO DUE WITH FILE ACCESS CONTROL ON MY COMPUTER
I had a problem that was partially solved. To explain it quickly : I
I had problem triggering server side button click events so I found a solution
Had a problem with the recursive conflictCheck() method. That seems fine now. I have
I had a Problem to use DotNet 4.0 DLL in a DotNet 2.0 Application,
i had a problem on confusing how to put ontouch inside my coding because

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.