Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135112

QRhiSwapChain (QD3D11SwapChain) createOrResize() crashes when importing D3D11 Device and Context

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8.2
    • Qt RHI
    • None
    • Windows

    Description

      I know, I have to attach minimal example, but the explanations below is quite clear.

      Create own ID3D11Device *d3dDevice and ID3D11DeviceContext *d3dContext by using D3D11CreateDevice(), where the first parameter pAdapter is valid IDXGIAdapter pointer from IDXGIFactory1::EnumAdapters()

      Now, import the device and context:

      QRhiD3D11NativeHandles nativeHandles;
      nativeHandles.dev = d3dDevice;
      nativeHandles.context = d3dContext;
      
      QRhi::Implementation m_curImpl= QRhi::D3D11;
      QRhiD3D11InitParams initParams;
      initParams.enableDebugLayer = true;
      
      QRhi * rhi = QRhi::create(m_curImpl,&initParams,{},&nativeHandles);

      rhi is a valid pointer.

      Later, in QWindow::resizeEvent() we have : QRhiSwapChain:createOrResize() and the actual call is QD3D11SwapChain::createOrResize()
      Since this is the first call, the member QD3D11SwapChain::swapChain is null and the code takes the true branch in "if (!swapChain) " qrhid3d11.cpp, line 5172.
      At line 5179 we have: QRhiD3D::outputDesc1ForWindow(m_window, rhiD->activeAdapter, &hdrOutputDesc)
      Note that rhiD->activeAapter is null.
      Then we have call to output6ForWindow(w, adapter, &out6) and ACCESS VIOLATION  at qrhid3dhepers.cpp line 20: for (UINT i = 0; adapter->EnumOutputs(i, &output) != DXGI_ERROR_NOT_FOUND; ++i)
      "adapter" variable is null.

      If we don't import device and context and allow QRhi::create to create its own,
       output6ForWindow() is called  with a valid IDXGIAdapter pointer for  adapter parameter.

      According to my debug, the crash is because when importing device and context, QRhiD3D11::create() does not set any value to QRhiD3D11::activeAdapter member.

      QRhiD3D11:QRhiD3D11() correctly initializes importedDeviceAndContext member to true.

      Then qrhid3d.cpp Line 243: if (!importedDeviceAndContext)
      In the false branch (we importing device and context) I don't see any activeAdapter assignment it remains null.

      The true branch correctly sets the activeAdapter member.

       

       

       

      Attachments

        For Gerrit Dashboard: QTBUG-135112
        # Subject Branch Project Status CR V

        Activity

          People

            lagocs Laszlo Agocs
            smacker Vladimir Ivanov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change