c++multithreadingvisual-studiodirectx-10

DirectX 10 IDXGISwapChain::GetBuffer Multithread CTD Error


I'm trying to create a multi-threaded program where all of the rendering is done on the primary thread while the message handling (and window creation) is done on a secondary thread. The following line of code SwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)&back_buffer); in the initialization function produces an access violation error (0xc0000005) when the initialization function is placed on the main thread.

How can I fix this error without placing the initialization function on the secondary thread?

EDIT: I have posted all of the relevant code here.


Solution

  • On line 49 of Application.cpp, while (HWindow != nullptr); was waiting for HWindow to become nullptr. But HWindow is initialized as nullptr and therefore the while loop would skip and try to initialize a window that hasn't been created yet.

    That line now reads while (HWindow == nullptr);. This means the loop runs until the window has been created, thereby blocking initialization of a window that doesn't exist.