Archived

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

Curios crash

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

I''m getting an access violation and I''m not really sure why, heres my main cpp file.
  /Globals
CDirect3D* d3dWindow;
CWindow* window;

CHardball* pGame = NULL;

void CleanUp()
{
	SafeDelete(pGame);
}

int WINAPI WinMain(	HINSTANCE hInstance, 
					HINSTANCE hPrevInstance, 
					LPSTR lpCmdLine, 
					int nCmdShow) 
{
	
	pGame = new CHardball();

	if(pGame->Init(d3dWindow,window,hInstance))
		pGame->GameLoop();

	CleanUp();

	return 0;
}  
Once Init is called in the main cpp file it jumps to here.
  bool CHardball::Init(CDirect3D* pD3DWindow,CWindow* pWin,HINSTANCE hInstance)
{
	pD3D = pD3DWindow;
	pWindow = pWin;

	pWindow->makeWindow(hInstance,"Hardball","Hardball",0,0,800,600);

	if(InitD3D())
		return InitGame();		
	else
		return false;
		
	return true;
}
bool CHardball::InitD3D()
{

	if(pD3D->Create(pWindow))
	{
		return true;
	}
	else
		return false;
}
  
The problem seems to occur when I call my makeWindow function defined in CWindow.
  void CWindow::makeWindow(HINSTANCE phInstance,char* szTitle,
						 char* className,int fp_iX, int fp_iY,
						 int width,int height)
{
	WNDCLASSEX winClass;

	hInstance = phInstance; //Crashes after the next step over i.e. (F11)

	winWidth  = width;
	winHeight = height;

	// Setup and register the window class

	winClass.cbSize         = sizeof(WNDCLASSEX); 
	winClass.style			= CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
	winClass.lpfnWndProc	= BasicWindowsProc; // Our static function  

	winClass.cbClsExtra		= 0;
	winClass.cbWndExtra		= 0; 
	winClass.hInstance		= hInstance; 
	winClass.hIcon			= LoadIcon(NULL, IDI_APPLICATION); 
	winClass.hCursor		= LoadCursor(NULL, IDC_ARROW); 
	winClass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH); 
	winClass.lpszMenuName	= NULL; 
	winClass.lpszClassName	= className; 
	winClass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

	//Register the window!!!!

	if(!RegisterClassEx(&winClass))
		return;

	// Create a fullscreen window, one that doesn''t have anything in it

	hWnd = CreateWindowEx(NULL,  
						  className,     
						  szTitle,  
						  WS_POPUP | WS_VISIBLE, 
					 	  fp_iX, fp_iY,
						  width, height,
						  NULL,NULL,
						  hInstance,NULL);	
}  

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It seems that you haven''t initialized the "CWindow* window" pointer in your main file so when you call the CWindow''s makeWindow method into CHardball''s Init method, it crashes your application...

Greets

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
BTW, you should initialize the "CDirect3D* d3dWindow" pointer too...if not, your application will crash when you reach the line

if(pD3D->Create(pWindow))

into bool CHardball::InitD3D()

Greets

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
No, what I mean is that you should allocate memory for window and d3dWindow pointers...you know...

window = new CWindow()
d3dWindow = new CDirect3D()

Greets

Share this post


Link to post
Share on other sites