Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID3D11Factory instead of ID3D11Factory1 #1989

Merged
merged 1 commit into from
Aug 1, 2018
Merged

ID3D11Factory instead of ID3D11Factory1 #1989

merged 1 commit into from
Aug 1, 2018

Conversation

matt77hias
Copy link
Contributor

While integrating the current version of ImGui, I kept failing the following assert of ImGui::NewFrame in my application:

IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts >GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");

However, the actual cause is not directly related to fonts and font atlases, but rather to ImGui's provided D3D11 bindings. In the code below, the first two if conditions are true and the third one is false, resulting in no device, device context and factory bindings. This is the case for my application, but not for the demo application provided with ImGui.

bool    ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context)
{
    // Get factory from device
    IDXGIDevice* pDXGIDevice = NULL;
    IDXGIAdapter* pDXGIAdapter = NULL;
    IDXGIFactory1* pFactory = NULL;

    if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK) // true
        if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK) // true
            if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK) // false
            {
                g_pd3dDevice = device;
                g_pd3dDeviceContext = device_context;
                g_pFactory = pFactory;
            }
    if (pDXGIDevice) pDXGIDevice->Release();
    if (pDXGIAdapter) pDXGIAdapter->Release();

    return true;
}

For obtaining a device and device context in my application, I go the other way around and start with a IDXGIFactory (whereas ImGui does use the default IDXGIAdapter).

When I replace both occurrences of IDXGIFactory1 with IDXGIFactory in imgui_impl_dx11.cpp, both my application and the provided demo application work correctly. This change is handled by this pull request. (Apparently, ImGui's provided D3D11 bindings do not really use the global variable g_pFactory at all. So I am not sure why there is such a variable in the first place and why it needs to be of type IDXGIFactory1?)

@ocornut ocornut merged commit 6011ddf into ocornut:master Aug 1, 2018
ocornut added a commit that referenced this pull request Aug 1, 2018
@ocornut
Copy link
Owner

ocornut commented Aug 1, 2018

Thanks @matt77hias this is merged. You are right this isn't used in master branch. The factory is used in the viewport branch and I have merged this part earlier in master with the intention of testing it, so your report is helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants