Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Unhandled exception when closing directx


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 sharksaw40   Members   -  Reputation: 100

Like
0Likes
Like

Posted 08 February 2012 - 11:54 AM

I am learning directx from directxtutorial.com and when I have compiled one of the samples and run it then close it I get an error message saying "Unhandled exception at 0x010a1883 in test.exe: 0xC0000005: Access violation reading location 0x00000000.". What does this mean? I have checked that I have typed out all the code correctly and copied and pasted the sample into VC++ which still gives me the error. I think the function causing the problem is:

void CleanD3D(void)
{
	swapchain->Release();
	dev->Release();
	devcon->Release();
}


There is a yellow arrow next to it (I'm a beginner and I'm not entirely sure what it means but I'm guessing it means there is an error on that line). I assume that the codes not the problem because I got it from a tutorial so it must be a configuration problem. Can someone tell help me find what could be wrong? The rest of the code is below:

#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")IDXGISwapChain *swapchain;
ID3D11Device *dev;
ID3D11DeviceContext *devcon;
void InitD3D(HWND hWnd);
void CleanD3D(void);LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW |CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass1";
RegisterClassEx(&wc);RECT wr = {0,0,800,600};
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);hWnd = CreateWindowEx(NULL, "WindowClass1", "Our first windowed program", WS_OVERLAPPEDWINDOW, 300, 100, wr.right - wr.left, wr.bottom - wr.top, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);InitD3D(hWnd);
MSG msg={0};while(TRUE)
{
  if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  {
   TranslateMessage(&msg);
   DispatchMessage(&msg);   if(msg.message == WM_QUIT)
	break;
  }
  else
  {
  }
}
	CleanD3D();
return msg.wParam;
}LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch(message)
{
case WM_DESTROY:
  {
   PostQuitMessage(0);
   return 0;
  } break;
}
return DefWindowProc(hWnd, message, wparam, lparam);
}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;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = hWnd;
scd.SampleDesc.Count = 4;
scd.Windowed = TRUE;
D3D11CreateDeviceAndSwapChain(NULL,
  D3D_DRIVER_TYPE_HARDWARE,
  NULL,
  NULL,
  NULL,
  NULL,
  D3D11_SDK_VERSION,
  &scd,
  &swapchain,
  &dev,
  NULL,
  &devcon);
}[color=#ff0000]void CleanD3D(void)
{
swapchain->Release();
dev->Release();
devcon->Release();
}[/color]

Thanks in advance

Sponsor:

#2 Washu   Senior Moderators   -  Reputation: 5362

Like
0Likes
Like

Posted 08 February 2012 - 11:56 AM

One of those pointers (or all of them) is null.

Unhandled exception at 0x010a1883 in test.exe: 0xC0000005: Access violation reading location 0x00000000.

Means: At the code address of 0x010a1883 you attempted to access memory location 0x00000000. This generated an access violation (0xC0000005).

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX


#3 Adam_42   Crossbones+   -  Reputation: 2574

Like
1Likes
Like

Posted 08 February 2012 - 12:11 PM

What's almost certainly happened is that D3D11CreateDeviceAndSwapChain() has failed. That means that dev, devcon and swapchain pointers are NULL. The tutorial code being from that site doesn't bother to check if it's failed, and the program crashes on exit trying to release them.

A simple fix for that crash is to do "if (swapchain != NULL) swapchain->Release();" and the same thing for the other three lines.

To get it functional I'd firstly suggest creating a debug device which should give you some output on the debug console telling you what's gone wrong. You could also try changing the driver type to D3D_DRIVER_TYPE_WARP which uses the software renderer and should help if you have hardware or driver issues.

// This is how you create a debug device
D3D11CreateDeviceAndSwapChain(NULL,
  D3D_DRIVER_TYPE_HARDWARE,
  NULL,
  D3D11_CREATE_DEVICE_DEBUG,
  NULL,
// ...


#4 sharksaw40   Members   -  Reputation: 100

Like
0Likes
Like

Posted 10 February 2012 - 11:38 AM

D3D_DRIVER_TYPE_WARP does make it work so it must be a hardware problem. I re-installed the driver but it still didn't fix. Does anyone know what I could do to use the hardware? Thanks for the help.

#5 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 10 February 2012 - 11:58 AM

That indicates that you're trying to do something your card doesn't support - and that particular site is nutoriously bad for checking that things succeed or are supported.

Steve Macpherson
Systems Programmer

Rockstar North


#6 Adam_42   Crossbones+   -  Reputation: 2574

Like
0Likes
Like

Posted 10 February 2012 - 02:16 PM

D3D_DRIVER_TYPE_WARP does make it work so it must be a hardware problem. I re-installed the driver but it still didn't fix. Does anyone know what I could do to use the hardware? Thanks for the help.


What graphics card do you have? Posting a dxdiag report would be helpful.

Also what error messages does the debug version print in the output window when you try and set up a hardware device?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS