Public Group

# An unhandled exception

This topic is 2940 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have been using direct x 9 to make a simple game, when I came across this error, the program would compile successfully apparently, but when I try to run it it tells me I have an unhandled exception. It used to work fine, the only difference is I tried to make the window creation process a class, rather then just a bunch of functions so I could make a hierarchy to make some child windows an stuff.
after saying I have this error, it takes me to these lines of code,
 void StartRender() { d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); // this one here is where it takes me d3ddev->BeginScene(); d3dspt->Begin(D3DXSPRITE_ALPHABLEND); return; } 
If anyone can think of any reasons why this might be occurring, it would be great to hear em, and if you'd like to see more code then that just ask.

##### Share on other sites
My first guess would be that you never actually initialize d3ddev, so the variable contains garbage. Hard to say without seeing the actual error message, though. (For reference - please always post the complete, exact text of errors when asking for help with them. Makes it a lot easier to figure out what's up.)

##### Share on other sites
"Unhandled exception at 0x00ff16e8 in KillGore's Level Creation!.exe: 0xC0000005: Access violation reading location 0x00000000." Is the error message.
I just kinda figured this error message didn't really give very much information, that's why I'm having so much trouble, normally a bit more information is given by the compiler as to what is wrong, but i dunno, maybe it makes more sense to you?

anyways, this may help, Here is my initializing function for direct 3d

void InitDirect3D(WindowCreator* gw) { d3d = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.Windowed = gw->Windowed; d3dpp.BackBufferWidth = gw->Width; d3dpp.BackBufferHeight = gw->Height; d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, gw->hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); D3DXCreateSprite(d3ddev, &d3dspt); return; }
as well as the window and then window creater class.
 //window.h #include "Directx.h" class Window { public: Window(WNDPROC winProc, char const * className, HINSTANCE hInst); void Register() { ::RegisterClass(&_class); } private: WNDCLASS _class; }; //window.cpp #include "Window.h" Window::Window(WNDPROC winProc, char const * className, HINSTANCE hInst) { _class.style = 0; _class.lpfnWndProc = winProc; _class.cbClsExtra = 0; _class.cbWndExtra = 0; _class.hInstance = hInst; _class.hIcon = 0; _class.hCursor = ::LoadCursor(0, IDC_ARROW); _class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); _class.lpszMenuName = 0; _class.lpszClassName = className; } 
// WindowCreater.h #include "Directx.h" struct WindowCreator { HWND hWnd; bool Windowed; int xStore; int yStore; int Width; int Height; WindowCreator(int x, int y, int w, int h, char const * caption, char const * className, HINSTANCE hInstance); void SetVisible(int cmdShow) { // Makes the window visible after it is created ::ShowWindow(hWnd, cmdShow); ::UpdateWindow(hWnd); } }; //WindowCreater.cpp #include "WindowCreater.h" WindowCreator::WindowCreator(int x, int y, int w, int h, char const * caption, char const * className, HINSTANCE hInstance) { hWnd = NULL; Windowed = false; xStore=x; yStore=y; Width=w; Height=h; hWnd = ::CreateWindow( className, // Name of the registered window class caption, // Window Caption to appear at the top of the frame WS_EX_TOPMOST|WS_CAPTION, // The style of window to produce xStore, // x position of the window yStore, // y position of the window Width, // width of the window Height, // height of the window 0, // The handle to the parent frame 0, // The handle to the menu for this window hInstance, // the application instance 0); // window creation data } 

##### Share on other sites
I notice you aren't checking for error codes when you call DirectX functions; that's the first thing to try. See if any of your calls (especially CreateDevice) are failing.

##### Share on other sites
Error codes? I don't actually know how to use those, and I'm having a bit of trouble trying to find some information on them on google, would you be able to explain or link me to somewhere where I could learn how to use em?.

##### Share on other sites
The error codes are the return values for the API functions. For instance IDirect3D9::CreateDevice() can return any of D3D_OK, D3DERR_DEVICELOST, D3DERR_INVALIDCALL, D3DERR_NOTAVAILABLE, D3DERR_OUTOFVIDEOMEMORY. If it returned D3D_OK, then the function succeeded. If it returned any of the other values, then the function didn't succeed and the exact return value will tell you why. For most COM functions, including most DirectX functions, the return values can be simply checked for success or failure using the FAILED() macro. You can also convert an error into a readable string using DXGetErrorDescription().

##### Share on other sites
Another common mistake is simply not calling the initialisation function you wrote, or calling it in the wrong order (which could cause one of the errors the guys mentioned above, or the access violation you see). Stepping through the code with a debugger might help you track down these kinds of problems.

##### Share on other sites
Thank you all for the help, I believe I may have found the answer, Thanks a lot for telling me about those error code, that helped me pinpoint what I believe is wrong, I have yet to test it out, but it should work. I knew it had to be something to do with the window creation from the start, as that's the only thing i changed from the working version, but kinda lost track of what i knew it had to be as i went on and yeah... Pretty sure it was something to do with the initializing of the window being messed up, but now it's time to test out my theory.<br>

##### Share on other sites
"Unhandled exception at 0x00ff16e8 in KillGore's Level Creation!.exe: 0xC0000005: Access violation reading location 0x00000000." Is the error message.
I just kinda figured this error message didn't really give very much information, that's why I'm having so much trouble, normally a bit more information is given by the compiler as to what is wrong, but i dunno, maybe it makes more sense to you?
That error message (combined with the line number where the exception occurred) tells you everything you need to know about the crash in order to fix it

Conveniently, today's aldevblogaday post explains that category of error messages in great detail -- read down to the section on virtual functions.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 13
• 30
• 9
• 16
• 12