Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


I'm cursed ...

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Even with copying from the SDK I''m cursed ... I''ve been trying for two days or so now to get direct x 8 setup, and still haven''t completely grasped it... Anyone know what this means? Unhandled exception at 0x004122f7 in Win32APP.exe: 0xC0000005: Access violation reading location 0x00000000.
#include <windows.h>
#include "d3d8.h" // Direct 3D

#include "d3dx8.h" // D3DX

// Other Dependencies

// Application Dimensions, Type, Class, and WindowName

#define WNDWIDTH	400
#define WNDHEIGHT	400
const char g_szClass[] = "GameClass";
const char g_szCaption[] = "GameClassTitle";
// Window Creation

HWND hWnd;

// DirectX

IDirect3D8* g_pD3D; // Direct3D Object

D3DDISPLAYMODE d3ddm; // Direct3D Display Mode

IDirect3DDevice8* g_pd3dDevice; // Device Interface


// Function Prototypes

							UINT uMsg,
							WPARAM wParam,
							LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, // Instance handle of the application

				   HINSTANCE hPrevInstance, // Unused

				   LPSTR lpCmdLine, // Command line options (if any)

				   int nCmdShow); // Show window flag

bool RegisterWindowClasses(HINSTANCE hInst, HWND& hWnd, WNDCLASSEX& wcex);
bool UnregisterWindowClasses(HINSTANCE hInst);

bool DoInit();
bool DoShutdown();

bool DoPreFrame();
bool DoFrame();
bool DoPostFrame();

void Render();

// Function Declarations

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

	// Register Window Classes

	if(RegisterWindowClasses(hInstance, hWnd, wcex) == false)
		return false;

	// Creates Direct3D Object

	if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
		return E_FAIL;
	// Sets Direct3D Display Mode

	if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
		return E_FAIL;

ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed   = TRUE;
d3dpp.BackBufferFormat = d3ddm.Format;

// Creates The direct3D device

                                  &d3dpp, &g_pd3dDevice ) ) )

	// Initilize Program Variables

	if(DoInit == false)
		return false;

	MSG msg; 
	while( GetMessage( &msg, NULL, 0, 0 ) )
		TranslateMessage( &msg );
		DispatchMessage( &msg );

	if(DoShutdown == false)
		// Shutdown Error

	// Destroy Window Class


	return 0;

		PostQuitMessage(0); // Tell windows to close application

	case WM_PAINT:
            ValidateRect( hWnd, NULL );
            return 0;

		// Pass remaining messages to message handler

		return DefWindowProc(hWnd, uMsg, wParam, lParam);
	return 0;
bool RegisterWindowClasses(HINSTANCE hInst, HWND& hWnd, WNDCLASSEX& wcex)
	// Register the window class.

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_CLASSDC;
	wcex.lpfnWndProc = WindowProc;
	wcex.cbClsExtra = 0L;
	wcex.cbWndExtra = 0L;
	wcex.hInstance = GetModuleHandle(NULL);
	wcex.hIcon = NULL;
	wcex.hCursor = NULL;
	wcex.hbrBackground = NULL;
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = g_szClass;
	wcex.hIconSm = NULL;
    if(!RegisterClassEx( &wcex ))
		return false;

    // Create the application''s window.

    hWnd = CreateWindow( g_szClass, g_szCaption, 
                              WNDTYPE, 0, 0, WNDWIDTH, WNDHEIGHT,
                              GetDesktopWindow(), NULL, wcex.hInstance, NULL );
	if(hWnd == NULL)
		return false;

	ShowWindow(hWnd, SW_SHOWNORMAL);

	return true;
bool UnregisterWindowClasses(HINSTANCE hInst)
	UnregisterClass(g_szClass, hInst);
	return true;

bool DoInit()

	return true;

bool DoShutdown()

	return true;

bool DoFrame()

	return false;
void Render()
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

Share this post

Link to post
Share on other sites
Access violation reading location 0x00000000

if (0x00000000 == NULL) {
//Then you are accessing memory at location zero which let's

// you know that the variable you are using is not properly

// initialised.


This portion of your code looks capable of being the culprit:

if(DoInit == false)
return false;

Did you mean SUCCEEDED here or is this a typo because your code will continue if you failed to create a D3D device instance but DoInit is equal to true?

Don't copy from the DirectX Docs! And don't assume that they are without error. The DirectX team spent their time making the API so kick-ass that they ended up copying most of the D3D8 code instead of writing D3D9 code and they probably didn't spend much time editing either.

Step through your programme with a debugger like the one included in Visual C++ and Borland which I assume you are using one or the other but I could be mistaken.

You can find my email by clicking on the profile tab and if you want to send me your project I would be more than happy to step through your code with a debugger as I know how frustrating DirectX can be when you're starting off.

[edited by - citizen3019 on January 14, 2004 2:56:55 AM]

Share this post

Link to post
Share on other sites
It seems to work better now, acually there were two things that were going on.

The sdk had suggested that I include WM_PAINT in the switch within the WindowProc. Problem was when the window was created windows sends a paint msg and dx tries to clear the screen before it''s even initialized.

The second was something I didn''t pick up, they encompassed that call you were referencing with an if tag so I didn''t realize that it wouldn''t have called it unless dx failed.

It seems the book I''m learning from is giving me the same problem with not telling me where to put the code, just disking it out like I know what it does and where it goes.

Share this post

Link to post
Share on other sites
I'm on 2b right now, and I can't seem to get past this error. LINK : fatal error LNK1104: cannot open file 'libci.lib'

At first it gave me linker errors because it couldn't find some functions in the lib files, so I used the method that the tutorials use instead of including them directly to the project. Now I get this error.

Why do I need this file?

[edited by - PumpkinPieman on January 16, 2004 12:38:34 PM]

Share this post

Link to post
Share on other sites
Are you using iostream.h or fstream.h or any similar header file? IIRC, libci.lib is the library for the old style iostream stuff.

Share this post

Link to post
Share on other sites
I''ve never seen that error. Very strange. Did you use the project file that came with the archive or did you make your own? If you made your own, try using the project file (and other files) exactly as they are when freshly downloaded and see if you still have the same problem.

Stay Casual,

Drunken Hyena

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!