Debug results

Started by
4 comments, last by CrazyCdn 17 years, 11 months ago
Okay, I have no Idea what is going on. It seems to be working fine but one of my error messages gets triggered... and it continues to run.... what is happening? My file:

// Austens Direct X.cpp : Defines the entry point for the application.
//
#include <windows.h>
#include <windowsx.h>
#include "stdafx.h"

#include <d3d9.h>
#include <d3dx9.h>
#include "Austens Direct X.h"

#define WIN32_LEAN_AND_MEAN


bool bactive = true;

bool Init();
bool Frame();
bool Shutdown();
void Error(int code);


LRESULT CALLBACK MsgHandler(
    HWND hwnd,     // window handle
    UINT msg,      // the message identifier
    WPARAM wparam, // message parameters
    LPARAM lparam  // more message parameters
);
//Initilize DirectX here


IDirect3D9 *iD3D=NULL;
IDirect3DDevice9 *iD3DDev=NULL;
HWND hwnd;

//Flexible Vertex Format

typedef struct {
  FLOAT x, y, z;     // 2-D coordinates
  FLOAT rhw;         // rhw
  FLOAT u, v;        // Texture coordinates
} sVertex;
#define VERTEXFVF (D3DFVF_XYZRHW | D3DFVF_TEX1)

IDirect3DVertexBuffer9 *iD3DVertBuf=NULL;
IDirect3DTexture9 *iD3DText=NULL;


int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{


WNDCLASSEX WindowsClass;                                   // declare structure variable

WindowsClass.cbSize =        sizeof(WNDCLASSEX);           // always use this!
WindowsClass.style =         CS_DBLCLKS | CS_OWNDC |
                            CS_HREDRAW | CS_VREDRAW;      // standard settings
WindowsClass.lpfnWndProc =   MsgHandler;                   // we need to write this!
WindowsClass.cbClsExtra =    0;                            // extra class info, not used
WindowsClass.cbWndExtra =    0;                            // extra window info, not used
WindowsClass.hInstance =     hinstance;                    // parameter passed to WinMain()
WindowsClass.hIcon =         LoadIcon(NULL, IDI_WINLOGO);  // Windows logo
WindowsClass.hCursor =       LoadCursor(NULL, IDC_ARROW);  // standard cursor
WindowsClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);  // a simple black brush
WindowsClass.lpszMenuName =  NULL;                         // no menu
WindowsClass.lpszClassName = TEXT("DirectX Test");                // class name
WindowsClass.hIconSm =       LoadIcon(NULL, IDI_WINLOGO);  // Windows logo again

RegisterClassEx(&WindowsClass);
MSG msg;


if (!(hwnd = CreateWindowEx(NULL,                   // extended style, not needed
                            TEXT("DirectX Test"),         // class identifier
                            TEXT("DirectX Test"),        // window title
                            WS_POPUP | WS_VISIBLE,  // parameters
                            0, 0, 800, 600,         // initial position, size
                            NULL,                   // handle to parent (the desktop)
                            NULL,                   // handle to menu (none)
                            hinstance,              // application instance handle
                            NULL))) // who needs it?
{
	Error(1);
}




Init();


while(bactive)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

Frame();



}

    return(0);
}

LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	switch(msg)
	{
	case WM_CREATE:
		//Initialize windows here
		return(0);
	
	case WM_QUIT:
		bactive = false;
		return(0);

	case WM_DESTROY:
		Shutdown();
		PostQuitMessage(0);
		return(0);

	case WM_CLOSE:
		DestroyWindow(hwnd);
		return(0);

	case WM_KEYDOWN:
		switch(wparam)
		{
		case VK_ESCAPE:
			SendMessage (hwnd, WM_DESTROY, NULL, 0) ;
			bactive = false;
			break;
		}
		return(0);
	}

    return(DefWindowProc(hwnd, msg, wparam, lparam));
}


bool Init()
{

	//Initilize DirectX formats and such

if((iD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
{
Error(2);
}

D3DDISPLAYMODE Display;
Display.Width = 1200;
Display.Height = 800;
Display.RefreshRate =0;
Display.Format = D3DFMT_A8R8G8B8;

if(FAILED(iD3D->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_A8R8G8B8, D3DFMT_A8R8G8B8, FALSE)))
{
	Error(3);
}

D3DPRESENT_PARAMETERS Present;
ZeroMemory(&Present, sizeof(D3DPRESENT_PARAMETERS));

Present.Windowed = false;
Present.SwapEffect = D3DSWAPEFFECT_FLIP;
Present.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
Present.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
Present.BackBufferFormat = Display.Format;
Present.BackBufferWidth = Display.Width;
Present.BackBufferHeight = Display.Height;

if(FAILED(iD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &Present, &iD3DDev)))
Error(7);

BYTE *Ptr;
  sVertex Verts[4] = {
      {  50.0f,  50.0f, 1.0f, 1.0f, 0.0f, 0.0f },
      { 350.0f,  50.0f, 1.0f, 1.0f, 1.0f, 0.0f },
      {  50.0f, 350.0f, 1.0f, 1.0f, 0.0f, 1.0f },
      { 350.0f, 350.0f, 1.0f, 1.0f, 1.0f, 1.0f }
    };

  iD3DDev->CreateVertexBuffer(sizeof(sVertex)*4, 0,VERTEXFVF, D3DPOOL_DEFAULT, &iD3DVertBuf, NULL);
  iD3DVertBuf->Lock(0,0, (void**)&Ptr, 0);
  memcpy(Ptr, Verts, sizeof(Verts));
  iD3DVertBuf->Unlock();
		D3DXCreateTextureFromFile(iD3DDev, TEXT("Texture.bmp"), &iD3DText);

return true;

}

bool Frame()
{

	// Clear device backbuffer
  iD3DDev->Clear(0, NULL, D3DCLEAR_TARGET,               
                        D3DCOLOR_RGBA(0,64,128,255), 1.0f, 0);

  // Begin scene
  if(SUCCEEDED(iD3DDev->BeginScene())) {

    // Set the vertex stream, shader, and texture
    iD3DDev->SetStreamSource(0, iD3DVertBuf, 0, sizeof(sVertex));
    iD3DDev->SetFVF(VERTEXFVF);
    iD3DDev->SetTexture(0, iD3DText);

    // Draw the vertex buffer
    iD3DDev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

    // Release texture
    iD3DDev->SetTexture(0, NULL);

    // End the scene
    iD3DDev->EndScene();
  }
  
  // Display the scene
  iD3DDev->Present(NULL, NULL, NULL, NULL);

return true;
}

bool Shutdown()
{
iD3D->Release();
iD3DDev->Release();
iD3DVertBuf->Release();
iD3DText->Release();
return true;
}

void Error(int code)
{
	MessageBox(NULL, TEXT("      An Error has interupted the program. Please check your error code against those commonly encountered in you manual. "),TEXT("Error has caused program halt"), MB_ICONERROR);
	SendMessage(NULL, WM_QUIT, NULL, NULL);
}
	

This was made using Microsoft Visual C++ 2005 And here is my debug log type thing:

'Austens Direct X.exe': Loaded 'C:\Documents and Settings\Admin\My Documents\C++ Projects\Direct X\Austens Direct X\debug\Austens Direct X.exe', Symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\d3d9.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\d3d8thk.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\version.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\lpk.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\usp10.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\Program Files\Common Files\Symantec Shared\AntiSpam\asOEHook.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\msvcr71.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\MSCTF.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\Program Files\ATI Technologies\ATI HYDRAVISION\HydraDMH.dll', Binary was not built with debug information.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\MSCTFIME.IME', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', No symbols loaded.
'Austens Direct X.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll', No symbols loaded.
First-chance exception at 0x004788af in Austens Direct X.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x004788af in Austens Direct X.exe: 0xC0000005: Access violation reading location 0x00000000.
The program '[1012] Austens Direct X.exe: Native' has exited with code 0 (0x0).

You might want to try and compile + run this yourself if it helps... You can respond to this, or if you prefer PM me or whatever suits you best :) Oh, also, for my error message, how do you use TEXT() to display a number? I want to embed the int code into the error message so I know what is happening? Any pointers? Thanks
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be
Advertisement
First-chance exception at 0x004788af in Austens Direct X.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x004788af in Austens Direct X.exe: 0xC0000005: Access violation reading location 0x00000000.

Reading location 0 = "Derefencing a null pointer"

You should be able to run your program in debug mode and discover the line that this happens on (hopefully it will break when this happens).

Oh, well now that I actually read the message you posted... you say an error message gets triggered. Check the logic of the program. I think you want to set your global (bactive) to false in your error function. If you don't do that, it will never quit. You should probably put WM_QUIT and WM_DESTROY together and have them do the same thing. Or at least they should both be setting (bactive) to false. But like I said, check your logic, I didn't write the code, I'm not exactly sure how you want to run things. It could be getting set somewhere that I don't see, but I'm pretty sure your problem has to do with that variable.
I usually check to see if the msg is WM_QUIT right after PeekMessage and break out of the loop then. Thats how most of the tutorials I've seen do it.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
I found the problem. I forgot to create the device. thanks for your help.

one more problem, when I hit escape, the directX portion closes, but the windows portion hangs around until I alt-f4 it. do I need to call unregister class?
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be
Quote:Original post by Plasmarobo
I found the problem. I forgot to create the device. thanks for your help.

one more problem, when I hit escape, the directX portion closes, but the windows portion hangs around until I alt-f4 it. do I need to call unregister class?


Yes, it needs to be called.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Syntax? I need that Unregisterclass syntax.
is it
Unregisterclass(HWND hwnd) ?
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be
It's UnregisterClass, searching google for Win32 function name + msdn is awesome ;-)

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

This topic is closed to new replies.

Advertisement