Skip to main content
gamedev.net
🔒 Locked

MFC Problem

Started by Galileo430 Jan 25, 2001 at 12:15 AM 2 replies 650+ views
Original Post
Galileo430
Galileo430
Ok so I''m writeing a editor for my game. Basicly it''s a SDI version of Worldcraft. When writeing the grid moving code I encountered a problem. Here is the source for it. NOTE: My grid only consists of a X and Z axis right now.
  
void CVistaEditorView::OnDraw(CDC* pDC)
{
	CVistaEditorDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	CPen	penGrid(PS_SOLID,1, RGB(0x00,0x00,0x00));

	pDC->SelectObject(&penGrid);

        //Fix out of View Grids.

	pDC->MoveTo(((m_iSizeX / 2) - m_lCenterX), 0);
	pDC->LineTo(((m_iSizeX / 2) - m_lCenterX), m_iSizeY);
	pDC->MoveTo( 0, ((m_iSizeY / 2) + m_lCenterZ));
	pDC->LineTo( m_iSizeX, ((m_iSizeY / 2) + m_lCenterZ));


}
void CVistaEditorView::OnRButtonUp(UINT nFlags, CPoint point) 
{
	m_bRightDown = false;
	
	CView::OnRButtonUp(nFlags, point);
}

void CVistaEditorView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	m_bRightDown = true;
	
	CView::OnRButtonDown(nFlags, point);
}

void CVistaEditorView::OnSize(UINT nType, int cx, int cy) 
{
	m_iSizeX = cx;
	m_iSizeY = cy;
	
	CView::OnSize(nType, cx, cy);
}

void CVistaEditorView::OnMouseMove(UINT nFlags, CPoint point) 
{
	if(m_bLeftDown == true && m_bRightDown == true)
	{
		m_lCenterX = m_lCenterX + (m_pntMouseLast.x - point.x);
		m_lCenterZ = m_lCenterZ - (m_pntMouseLast.y - point.y);
		Invalidate(TRUE);
	}



	m_pntMouseLast = point;
	
	CView::OnMouseMove(nFlags, point);
}

void CVistaEditorView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	m_bLeftDown = false;
	
	CView::OnLButtonUp(nFlags, point);
}

void CVistaEditorView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	m_bLeftDown = true;
	
	CView::OnLButtonDown(nFlags, point);
}
  
I found that after a certain amount of times I Invalidate the view.. I get... Warning: Uncaught exception in WindowProc (returning 0). First-chance exception in VistaEditor.exe (MSVCRTD.DLL): 0xE06D7363: Microsoft C++ Exception. Then the grid dissapears. I scrapped the application once before because of this problem. I can''t seem to find the problem
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Gorky
Gorky
Try adding this to OnDraw



CVistaEditorDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CPen penGrid(PS_SOLID,1, RGB(0x00,0x00,0x00));
CPen *pOldPen = pDC->SelectObject(&penGrid); //Fix out of View Grids.

pDC->MoveTo(((m_iSizeX / 2) - m_lCenterX), 0);
pDC->LineTo(((m_iSizeX / 2) - m_lCenterX), m_iSizeY);
pDC->MoveTo( 0, ((m_iSizeY / 2) + m_lCenterZ));
pDC->LineTo( m_iSizeX, ((m_iSizeY / 2) + m_lCenterZ));

pDC->SelectObject(pOldPen );




What I''m guessing is happening is this.
First time in, all is ok.
But you have selected a local variable pen, to become the pen to use from now on. Not just in this function.

Then when function ends, this pen goes out of scope.
Later OnDraws try to pass back a bad pen in SelectObject.
Galileo430
Galileo430
Got it, Thank you..

Never would have found it without ya.

Edited by - Galileo430 on January 25, 2001 7:02:06 PM
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Shannon Barber
Shannon Barber
Comment code out until the exception goes away, try to narrow down where it is, then put breaks points there to trace what''s exploding.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

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

Sign in to reply to this topic.