Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9163563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:28:30+00:00 2026-06-17T14:28:30+00:00

This fails on the ClearRenderTargetView call. Im not sure where my error is –

  • 0

This fails on the ClearRenderTargetView call.
Im not sure where my error is – im following a tutorial and i hvae no clue what is incorrect.
Would appreciate some help, thanks guys!

// DX6.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "DX6.h"
#include <d3d11.h>
#include <d3dx11.h>
#include <d3d10.h>
#include <d3dx9core.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")

//forward declares
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
void InitD3D(HWND hWnd);     // sets up and initializes Direct3D
void RenderFrame(void);
void CleanD3D(void);         // closes Direct3D and releases memory

// Global Variables:
HWND hWnd;
HINSTANCE hInst;
IDXGISwapChain *swapchain;             // the pointer to the swap chain interface
ID3D11Device *dev;                     // the pointer to our Direct3D device interface
ID3D11DeviceContext *devcon;           // the pointer to our Direct3D device context
ID3D11RenderTargetView *backbuffer;    // global declaration




int APIENTRY _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
{
    WNDCLASSEX wc;
    ZeroMemory(&wc,sizeof(WNDCLASSEX));
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass1";
    RegisterClassEx(&wc);

    // TODO: Place code here.
    MSG msg={0};

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(L"WindowClass1", L"Test Title", WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return 1;
   }

   ShowWindow(hWnd, nCmdShow);

    // Main message loop:
    while (true)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // translate keystroke messages into the right format
            TranslateMessage(&msg);

            // send the message to the WindowProc function
            DispatchMessage(&msg);

            // check to see if it's time to quit
            if(msg.message == WM_QUIT)
                break;
        }
        else{
            RenderFrame();
        }
    }

    return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // TODO: Add any drawing code here...
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

//D3D
void InitD3D(HWND hWnd){
    DXGI_SWAP_CHAIN_DESC scd;
    ZeroMemory(&scd,sizeof(DXGI_SWAP_CHAIN_DESC));

    scd.BufferCount=1;
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit color
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be used
    scd.OutputWindow = hWnd;                                // the window to be used
    scd.SampleDesc.Count = 4;                               // how many multisamples
    scd.Windowed = TRUE;  
    D3D11CreateDeviceAndSwapChain(NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,NULL,NULL,NULL,D3D11_SDK_VERSION,&scd,&swapchain,&dev,NULL,&devcon);

    ID3D11Texture2D *pBackBuffer;
    swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);

    // use the back buffer address to create the render target
    dev->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer);
    pBackBuffer->Release();

    // set the render target as the back buffer
    devcon->OMSetRenderTargets(1, &backbuffer, NULL);

    //create viewport
    D3D11_VIEWPORT viewport;
    ZeroMemory(&viewport,sizeof(D3D11_VIEWPORT));
    viewport.TopLeftX=0;
    viewport.TopLeftY=0;
    viewport.Width=800;
    viewport.Height=800;

    //set viewport
    devcon->RSSetViewports(1,&viewport);


}
void RenderFrame(void){
    //FAILS HERE!!!
   //Unhandled exception at 0x002e1a9f in DX6.exe: 0xC0000005: Access violation       //reading location 0x00000000.
    devcon->ClearRenderTargetView(backbuffer,D3DXCOLOR(0.0f,0.2f,0.4f,1.0f));

    //switch back & front buffer
    swapchain->Present(0,0);
}

void CleanD3D()
{
    // close and release all existing COM objects
    swapchain->Release();
    dev->Release();
    devcon->Release();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:28:31+00:00Added an answer on June 17, 2026 at 2:28 pm

    You never call InitD3D, so when CreateRenderTargetView is called in RenderFrame the backbuffer has not been set yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure why one snippet works while the other fails: This fails(the app quits)
This fails, not surprisingly: >>> 'abc' << 8 Traceback (most recent call last): File
short s; s = (EitherTrueOrFalse()) ? 0 : 1; This fails with: error CS0266:
This code fails on some machines: // Parse error: syntax error, unexpected '[' ...
For some reason, this MySQL fails: CREATE SCHEMA IF NOT EXISTS `partB` DEFAULT CHARACTER
This works as expected: SELECT Mike AS FName This fails with the error Query
The following fails with the error prog.cpp:5:13: error: invalid conversion from ‘char’ to ‘const
This fails string temp = () => {return test;}; with the error Cannot convert
I am using ExtrernalInterface.call(javascript_function, args); to call javascript functions from Flex. But this fails
Why this fails to compile: scala> val a? = true <console>:1: error: illegal start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.