Skip to main content
gamedev.net
🔒 Locked

Run-time error #3

Started by Azteroth 0 replies 400+ views
Original Post
Azteroth
Azteroth
Hi I've been working on the ZFX engine and I am finally running into an error about a variable(msg) not being initialized at run-time don't know what to do thanks ahead if you can provide help.

#define WIN32_MEAN_AND_LEAN

#include "AzRenderer.h"
#include "Az.h"		
#include "main.h"

#pragma comment(lib, "AzRenderer.lib")

HWND		g_hWnd	= NULL;
HINSTANCE	g_hInst	= NULL;
TCHAR		g_szAppClass[] = TEXT("FrameWorkTest");

BOOL		g_bIsActive	= FALSE;
bool		g_bDone		= false;
FILE		*pLog		= NULL;

LPAZRENDERER		g_pRenderer = NULL;
LPAZRENDERDEVICE	g_pDevice	= NULL;

int WINAPI WinMain(HINSTANCE hInst,
				   HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX		wndclass;
	HRESULT			hr;
	HWND			hWnd;
	MSG				msg;

	wndclass.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	wndclass.cbSize			= sizeof(wndclass);
	wndclass.lpfnWndProc	= MsgProc;
	wndclass.cbClsExtra		= 0;
	wndclass.cbWndExtra		= 0;
	wndclass.hInstance		= hInst;
	wndclass.hCursor		= LoadCursor(NULL,IDC_ARROW);
	wndclass.hbrBackground	= (HBRUSH)(COLOR_WINDOW);
	wndclass.lpszMenuName	= NULL;
	wndclass.lpszClassName	= g_szAppClass;
	wndclass.style			= CS_HREDRAW|CS_VREDRAW|
								CS_OWNDC|CS_DBLCLKS;


	if(RegisterClassEx(&wndclass) == 0)
		return 0;

	if(!(hWnd = CreateWindowEx(NULL,g_szAppClass,
								TEXT("Cranking up AzEngine..."),
								WS_OVERLAPPEDWINDOW|WS_VISIBLE,
								GetSystemMetrics(SM_CXSCREEN)/2-190,
								GetSystemMetrics(SM_CYSCREEN)/2-140,
								380,280,NULL,NULL,hInst,NULL)))
		return 0;

	g_hWnd = hWnd;
	g_hInst	= hInst;

	pLog = fopen("log_main.txt", "w");

	if(FAILED(hr = ProgramStartup("Direct3D")))
	{
		fprintf(pLog, "error: ProgramStartup() failed\n");
		g_bDone = true;
	}
	else if(hr == AZ_CANCELED)
	{
		fprintf(pLog, "ProgramStarup() canceled\n");
		g_bDone = true;
	}
	else
		g_pDevice->SetClearColor(0.1f, 0.3f, 0.1f);

	while(!g_bDone)
	{
		while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		
		if(g_bIsActive)
		{
			if(g_pDevice->IsRunning())
			{
				g_pDevice->BeginRendering(true,true,true);
				g_pDevice->EndRendering();
			}
		}
	}
	ProgramCleanup();

	UnregisterClass(g_szAppClass, hInst);

	return (int)msg.lParam;// This is where my error says its at
}

LRESULT WINAPI MsgProc(HWND hWnd, UINT msg,
					   WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_ACTIVATEAPP:
		{
			g_bIsActive = (BOOL)wParam;
		}break;
	case WM_KEYDOWN:
		{
			switch(wParam)
			{
			case VK_ESCAPE:
				{
					g_bDone = true;
					PostMessage(hWnd, WM_CLOSE, 0, 0);
					return 0;
				}break;
			}
		}break;
	case WM_DESTROY:
		{
			g_bDone = true;
			PostQuitMessage(0);
			return 1;
		}break;
	default: break;
	}
	return DefWindowProc(hWnd, msg,wParam,lParam);
}

HRESULT ProgramStartup(char *chAPI)
{
	HWND	hWnd3D[4];
	RECT	rcWnd;
	int		x=0,y=0;

	if(strcmp(chAPI,"OpenGL")==0)
		return S_OK;

	g_pRenderer = new AzRenderer(g_hInst);

	if(FAILED(g_pRenderer->CreateDevice(chAPI)))
		return E_FAIL;

	g_pDevice = g_pRenderer->GetDevice();
	if(g_pDevice == NULL) 
		return E_FAIL;

	GetClientRect(g_hWnd, &rcWnd);

	for(int i=0;i<4;i++)
	{
		if((i==0)||(i==2))x=10;
		else x = rcWnd.right/2+10;

		if((i==0)||(i==1))y=10;
		else y = rcWnd.bottom/2+10;

		hWnd3D = CreateWindowEx(WS_EX_CLIENTEDGE,
									TEXT("static"),NULL,WS_CHILD|
									SS_BLACKRECT|WS_VISIBLE, x, y,
									rcWnd.right/2-20, rcWnd.bottom/2-20,
									g_hWnd,NULL,g_hInst,NULL);
	}

	return g_pDevice->Init(g_hWnd,
							hWnd3D,
							4, 
							16,
							0,
							false);
}

HRESULT ProgramCleanup(void)
{
	if(g_pRenderer)
	{
		delete g_pRenderer;
		g_pRenderer = NULL;
	}
	if(pLog)
	{
		fclose(pLog);
		pLog = NULL;
	}

	return S_OK;
}
Azteroth
Lord_Evil
Lord_Evil
Seems like the message object is destroyed (or never initialized if the message loop isn't entered at all). I don't know exactly but UnregisterClass(g_szAppClass, hInst); could cause the message object to be destroyed. Try to grab the lparam before calling that.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.