Jump to content
  • Advertisement

Archived

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

Sabonis

Access violations

This topic is 5735 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

when i run this code, i get an access violation error when debugging at GetAdapterDisplayMode function.. Can someone pls help? and can someone pls tell me how to put all that code in a scroll box so i dont piss off the admins? #define WIN32_LEAN_AND_MEAN // The main windows include file #include <windows.h> #include <stdlib.h> #include <d3d8.h> #include <d3dx8.h> int GameInit(); int GameLoop(); int GameShutdown(); LPDIRECT3D8 g_pD3D = 0; LPDIRECT3DDEVICE8 g_pDevice = 0; HWND g_hWndMain; void SetError( char* String ) { OutputDebugString( String); OutputDebugString( "\n" ); } // The window procedure to handle events long CALLBACK WndProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT PaintStruct; // Structure used during windows painting HDC hDC; // Handle to device context for painting // Switch the windows message to figure out what it is switch( uMessage ) { case WM_CREATE: // The CreateWindow() function was just called { // One Time Initialization return 0; } case WM_PAINT: // The window needs to be redrawn { // Tell windows we want to start updating the window hDC = BeginPaint( hWnd, &PaintStruct ); //Tell windows we have finished updating the window EndPaint( hWnd, &PaintStruct ); return 0; } case WM_DESTROY: // The window is about to be closed { // Our main window is closing. This means we want our app to exit. // Tell windows to put a WM_QUIT message in our message queue PostQuitMessage( 0 ); return 0; } default: // Some other message { // Let windows handle this message return DefWindowProc( hWnd, uMessage, wParam, lParam ); } } } // The windows entry point. The application will start executing here int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pstrCmdLine, int iCmdShow ) { HWND hWnd; // The handle to our main window MSG msg; // The message windows is sending us WNDCLASSEX wc; // The window class used to create our window // The name of our class and also the title to our window static char strAppName[] = "First Windows App, CGM style"; //LOGBRUSH CrossHatchBrush; //CrossHatchBrush.lbStyle = BS_HATCHED; //CrossHatchBrush.lbColor = RGB(255,0,255); //CrossHatchBrush.lbHatch = HS_DIAGCROSS; //HBRUSH hCrossBrush = CreateBrushIndirect(&CrossHatchBrush); // Fill in the window class with the attributes for our main window // The size of this struture in bytes wc.cbSize = sizeof( WNDCLASSEX ); // The style of the window. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Useless information. Just set to zero. wc.cbClsExtra = 0; // Useless information. Just set to zero. wc.cbWndExtra = 0; // The name of our event handler wc.lpfnWndProc = WndProc; // A handle to the applications instance wc.hInstance = hInstance; // The handle to the brush to use for the window background wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); // A handle to the icon to use for the window wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); // A handle to a smaller version of the apps icon wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION ); // A handle to the cursor to use while the mouse is over our window wc.hCursor = LoadCursor( NULL, IDC_CROSS ); // A handle to the resource to use as our menu wc.lpszMenuName = NULL; // The human readable name for this class wc.lpszClassName = strAppName; // Register the class with windows RegisterClassEx( &wc ); // Create the window based on the previous class hWnd = CreateWindowEx( NULL, // Advanced style settings strAppName, // The name of the class strAppName, // The window caption WS_OVERLAPPEDWINDOW,// The window style CW_USEDEFAULT, // The initial x position CW_USEDEFAULT, // The initial y position 850, 650, // The intiial width / height NULL, // Handle to parent window NULL, // Handle to the menu hInstance, // Handle to the apps instance NULL ); // Advanced context g_hWndMain = hWnd; // Display the window we just created ShowWindow( hWnd, iCmdShow ); // Draw the window contents for the first time UpdateWindow( hWnd ); if( FAILED (GameInit() ) ) { SetError("Initialization failed"); GameShutdown(); return E_FAIL; } // Start the message loop while( TRUE ) { // Check if a message is waiting for processing if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { // Check if the message is to quit the application if( msg.message == WM_QUIT ) // Exit the message loop break; // Change the format of certain messages TranslateMessage( &msg ); // Pass the message to WndProc() for processing DispatchMessage( &msg ); } else { GameLoop(); } } GameShutdown(); // Return control to windows with the exit code return msg.wParam; } int GameInit() { HRESULT r = 0; D3DDISPLAYMODE d3ddm; D3DPRESENT_PARAMETERS d3dpp; g_pD3D = Direct3DCreate8( D3D_SDK_VERSION); if(g_pD3D = NULL) { SetError( "Could not create IDirect3D Object" ); return E_FAIL; } r = g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm); if(FAILED(r)) { SetError( "Could not get display adapter information"); return E_FAIL; } ZeroMemory( &d3dpp, sizeof( D3DPRESENT_PARAMETERS )); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; r = g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWndMain, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pDevice); if( FAILED(r) ) { SetError("Could not create the render device"); return E_FAIL; } return S_OK; } int GameLoop(){ return S_OK; } int GameShutdown() { if( g_pDevice) { g_pDevice->Release(); } if(g_pD3D) { g_pD3D->Release(); } return S_OK; }

Share this post


Link to post
Share on other sites
Advertisement
Hi Sabonis.

If you haven''t figured it out yet, this statement:

if(g_pD3D = NULL)

is setting your IDirect3D8 interface pointer to NULL. Try using:

if(g_pD3D == NULL)

instead. Or possibly use FAILED() as you have used elsewhere.

To get your source code into a format like I have used, use [ code ] and [ / code ] tags, without the spaces. To put the code into a scrolling box, use [ source ] and [ / source ] tags.

Share this post


Link to post
Share on other sites


else
{
GameLoop();
}



I think you want to process game stuff every frame, not just the ones that don''t have a windows message with ''em.

in WM_PAINT: you might not want to use GDI Stuff there. I''m not sure, but I think that it has a chance of messing with your surfaces. I''d use ValidateRect().

yeah, what he said is true, you are making your pointer NULL. I''ve done that from time to time...

and once you get your game loop going, I''d do some error checking in the
 while(true)  
loop.

Just some thoughts.

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!