tags:

views:

21

answers:

1

I have got a crash at calling function Clearrendertargetview().

Below is the code:

HWND hwnd;

    ID3D10Device* device;
    IDXGISwapChain* swapChain;
    ID3D10RenderTargetView* renderTarget;
    D3D10_VIEWPORT  viewPort;

DXGI_SWAP_CHAIN_DESC swapchaind;

    SecureZeroMemory(&swapchaind, sizeof(DXGI_SWAP_CHAIN_DESC));

    swapchaind.BufferCount = 2;
    swapchaind.OutputWindow = hwnd;
    swapchaind.BufferDesc.Height = height;
    swapchaind.BufferDesc.Width = width;
    swapchaind.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    swapchaind.BufferDesc.RefreshRate.Numerator = 60;
    swapchaind.BufferDesc.RefreshRate.Denominator = 1;
    swapchaind.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapchaind.Windowed = true;
    swapchaind.SampleDesc.Count = 1;
    swapchaind.SampleDesc.Quality = 0;
    device = NULL;
    swapChain = NULL;
    if(FAILED(D3D10CreateDeviceAndSwapChain(NULL,
                                    D3D10_DRIVER_TYPE_HARDWARE,
                                    NULL,
                                    NULL,
                                    D3D10_SDK_VERSION,
                                    &swapchaind,
                                    &swapChain,
                                    &device))) exit(11);

    ID3D10Texture2D*  backbuffer;
    if(FAILED(swapChain->GetBuffer(0, _uuidof(ID3D10Texture2D), (void**)&backbuffer))) exit(12);
    if(FAILED(device->CreateRenderTargetView(backbuffer, NULL, &renderTarget))) exit(13);
    backbuffer->Release();
    device->OMGetRenderTargets(1, &renderTarget, NULL);

    viewPort.Height = height;
    viewPort.Width = width;
    viewPort.MaxDepth = 1.0f;
    viewPort.MinDepth = 0.0f;
    viewPort.TopLeftX = 0;
    viewPort.TopLeftY = 0;

    device->RSSetViewports(1, &viewPort);
float clearColor[4] = {0.0f,0.0f,1.0f,1.0f};
device->ClearRenderTargetView(renderTarget, clearColor); //da crash iz here
renderFunc();//rendering
swapChain->Present(0,0);

Where am I wrong?

+1  A: 
device->OMGetRenderTargets(1, &renderTarget, NULL);

Don't you rather want

device->OMSetRenderTargets(1, &renderTarget, NULL);
Bahbar
Oh thanks, that solved it! :)