Search code examples
direct3ddxut

L"To fix call CDXUTDialog::Init() first. See comments for details."


After calling callback function DXUTCreateDevice() error is being returned from DXUTgui.cpp assert checking. Assert says first call CDXUTDialog::Init() but where should i put it in WinMain() ? enter image description here


Solution

  • Compare your DXUT client code to the content of EmptyProject and SimpleSample--assuming you are using the DXUT11 from GitHub.

    The typical pattern is to create a global variable for CDXUTDialogResourceManager, and then call CDXUTDialog::Init from InitApp before you get a callback from DXUTCreateDevice

    int WINAPI wWinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow ) 
    { 
        // Enable run-time memory check for debug builds. 
    #ifdef _DEBUG 
        _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 
    #endif 
    
    
        // DXUT will create and use the best device 
        // that is available on the system depending on which D3D callbacks are set below 
    
    
        // Set DXUT callbacks 
        DXUTSetCallbackMsgProc( MsgProc ); 
        DXUTSetCallbackKeyboard( OnKeyboard ); 
        DXUTSetCallbackFrameMove( OnFrameMove ); 
        DXUTSetCallbackDeviceChanging( ModifyDeviceSettings ); 
    
    
        DXUTSetCallbackD3D11DeviceAcceptable( IsD3D11DeviceAcceptable ); 
        DXUTSetCallbackD3D11DeviceCreated( OnD3D11CreateDevice ); 
        DXUTSetCallbackD3D11SwapChainResized( OnD3D11ResizedSwapChain ); 
        DXUTSetCallbackD3D11SwapChainReleasing( OnD3D11ReleasingSwapChain ); 
        DXUTSetCallbackD3D11DeviceDestroyed( OnD3D11DestroyDevice ); 
        DXUTSetCallbackD3D11FrameRender( OnD3D11FrameRender ); 
    
        InitApp();  <-- // THIS IS WHERE DXUT GUI WIDGETS GET INITIALIZED, BEFORE THE WINDOW OR DEVICE IS CREATED
        DXUTInit( true, true, nullptr ); // Parse the command line, show msgboxes on error, no extra command line params 
        DXUTSetCursorSettings( true, true ); 
        DXUTCreateWindow( L"SimpleSample11" ); 
    
    
        // Only require 10-level hardware, change to D3D_FEATURE_LEVEL_11_0 to require 11-class hardware 
        // Switch to D3D_FEATURE_LEVEL_9_x for 10level9 hardware 
        DXUTCreateDevice( D3D_FEATURE_LEVEL_10_0, true, 800, 600 ); 
    
    
        DXUTMainLoop(); // Enter into the DXUT render loop 
    
    
        return DXUTGetExitCode(); 
    } 
    

    Starting a new project using DXUT is not recommended. It's really intended only for maintaining existing code that has dependencies on DXUT while removing dependencies on D3DX11 and other legacy DirectX SDK content. The vast majority of DXUT's functionality is complete overkill for most applications. It's also buggy and really only intended for samples.