سؤال

I got a simple Direct3D program running from an example in a book. It creates first a win 32 window and then a blank Direct3D scene. I am trying to completely re-jig the code so it is more modular and in a style I am more comfortable with.

Right now it is crashing when I call my Render function. The function is:

void Render(void)
{

    float clearColor[4] = { 0.0f, 0.0f, 0.25f, 1.0f };
    d3dContext_->ClearRenderTargetView(backBufferTarget_, clearColor);
    swapChain_->Present(0, 0);

}

The wWinMain function is as follows:

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow)
{
InitWindow();

InitD3D();

InitScene();

while (!progFinished)
{

    MessagePump(); 

    Render(); 
}
return 0;
}

As far as I can see it is crashing when it hits the d3dContext_->ClearRenderTargetView(backBufferTarget_, clearColor); The original code has the render function as:

    while( msg.message != WM_QUIT )
{
    if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
    else
    {
    // Update and Draw
    demo->Update( 0.0f ); 
    demo->Render( ); 
    }
}

where I have taken the needed components out of the demo header and implementation file. I think I just do not fully understand where the DirectX 'information' is that allows it to continue the display procedure. Any help would be greatly appreciated.

هل كانت مفيدة؟

المحلول

I forgot to update this for the answer. The problem was in an area of code I did not present:

HWND hwnd = CreateWindowA("DX11BookWindowClass", "Blank Win32 Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance, NULL);

HWND was previously defined as global, then locally again here. All I had to do was remove HWND and it worked.

Thanks

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top