CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Location
    Germany
    Posts
    487

    Why does this code crash?

    Hi!
    The following code crashes when run as release build. When run as a debug-build it works fine. The called dialog mainly contains a charting control.

    Code:
    void CServiceView::OnButtonGraph()   { 
         CDialogGraph m_DialogGraph;
         m_DialogGraph.DoModal();
        //CRASH happens after this line!
    }
    Any hint?



    The called dialog is shown from here. The crash is independend from any action taken inside the dialog. Before you blame my bad coding style, I want to point out that I'm still a beginner and I still need many hints from guys like you.
    Code:
    // DialogGraph.cpp: Implementierungsdatei
    //
    
    #include "stdafx.h"
    #include "defines.h"
    #include "Typedef.h"
    #include "globals.h"
    #include "Service.h"
    #include "DialogGraph.h"
    #include "DialogGraphSettings.h"
    // removed: some defined numbers
    
    const UINT WM_REC_GRAPH_VAL  = RegisterWindowMessage("PSR_SERVICE_PROGRAM:WM_REC_GRAPH_VAL" );
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    uint16 ValCount = 0;
    uint16 ValCountMax = VALCOUNTMAX;
    uint16 CurveArray[20];
    
    
    volatile HWND HwndGraphDlg;
    /////////////////////////////////////////////////////////////////////////////
    // Dialogfeld CDialogGraph 
    
    
    
    CDialogGraph::CDialogGraph(CWnd* pParent /*=NULL*/)
    	: CDialog(CDialogGraph::IDD, pParent)
    {
    	//{{AFX_DATA_INIT(CDialogGraph)
    		// HINWEIS: Der Klassen-Assistent fügt hier Elementinitialisierung ein
    	//}}AFX_DATA_INIT
    }
    
    
    void CDialogGraph::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CDialogGraph)
    		// HINWEIS: Der Klassen-Assistent fügt hier DDX- und DDV-Aufrufe ein
    	//}}AFX_DATA_MAP
    }
    
    
    BEGIN_MESSAGE_MAP(CDialogGraph, CDialog)
    	ON_REGISTERED_MESSAGE(WM_REC_GRAPH_VAL, OnReceiveVal)
    	//{{AFX_MSG_MAP(CDialogGraph)
    	ON_BN_CLICKED(IDC_BUTTON_RUN, OnButtonRun)
    	ON_BN_CLICKED(IDC_BUTTON_CONFIG, OnButtonConfig)
    	ON_WM_SIZE()
    	ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
    	ON_BN_CLICKED(IDC_BUTTON_CLEAR_GRAPH, OnButtonClearGraph)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // Behandlungsroutinen für Nachrichten CDialogGraph 
    
    void CDialogGraph::OnButtonRun() 
    {
    	TRACE("\r\nIN: CDialogGraph::OnButtonRun");
    	WritingGraph = true;
    	TRACE("\r\nOUT: CDialogGraph::OnButtonRun");
    }
    
    
    void CDialogGraph::OnButtonStop() 
    {
    	TRACE("\r\nIN: CDialogGraph::OnButtonStop");
    	WritingGraph = false;
    	TRACE("\r\nOUT: CDialogGraph::OnButtonStop");
    }
    
    
    BOOL CDialogGraph::OnInitDialog() 
    {
    	int k;
    	TRACE("\r\nIN: CDialogGraph::OnInitDialog");
    	m_Graph.SetInnerColor (RGB(255,255,255));
    	m_Graph.SetShowLegend (true);
    	WillGraphVerlassen = false;
    
    	HwndGraphDlg = GetSafeHwnd();
    
    	for (int i = 0; i < 11; i++) {  //loop through the graphs
    		for (k = 0; k <= ValCountMax; k++) {
    			m_ValuesGraph[i][k].fXVal = 0;
    			m_ValuesGraph[i][k].fYVal = 0;
    		}
    	}
    
    	CDialog::OnInitDialog();
    	TRACE("\r\nOUT: CDialogGraph::OnInitDialog, returning TRUE");
    	return TRUE;  // return TRUE unless you set the focus to a control
    	              // EXCEPTION: OCX-Eigenschaftenseiten sollten FALSE zurückgeben
    }
    
    
    LRESULT CDialogGraph::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
    {
    //	TRACE("\r\nIN: CDialogGraph::WindowProc");
    	if (message == XG_RBUTTONUP) {
    		CPoint point;
    		GetCursorPos(&point);
    		ScreenToClient(&point);
    		CMenu menu;
    		menu.CreatePopupMenu (); 
    		menu.AppendMenu( MF_STRING, IDM_SELECT, "Select");
    		menu.AppendMenu( MF_STRING, IDM_ZOOM, "Zoom");
    		menu.AppendMenu( MF_STRING, IDM_RESET, "Reset");
    		menu.AppendMenu( MF_STRING, IDM_PAN, "Pan");
    		menu.AppendMenu( MF_STRING, IDM_CURSOR, "Cursor");
    		menu.AppendMenu( MF_STRING, IDM_INSERTLABEL, "Insert label");
    		menu.AppendMenu( MF_STRING, IDM_PRINT, "Print");
    		menu.AppendMenu( MF_SEPARATOR );
    		menu.AppendMenu( MF_STRING, IDM_PROPERTIES, "Properties");
    		ClientToScreen(&point);
    		UINT nCmd = menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_NONOTIFY,
    										  point.x, point.y , (CXGraph*)lParam);
    	}
    //	TRACE("\r\nOUT: CDialogGraph::WindowProc");
    	return CDialog::WindowProc(message, wParam, lParam);
    }
    
    void CDialogGraph::LoescheGrafik()
    {
    	int z;
    	int i;
    
    	m_Graph.ResetAll();
    	OnButtonStop();
    
    	z = m_Graph.GetCurveCount();
    	for (i = 0; i < z; i++) {
    		m_Graph.DeleteCurve(i);
    	}
    	z = m_Graph.GetXAxisCount();
    	for (i = 0; i < z; i++) {
    		m_Graph.DeleteXAxis(i);
    	}
    	z = m_Graph.GetYAxisCount();
    	for (i = 0; i < z; i++) {
    		m_Graph.DeleteYAxis(i);
    	}
    
    	for (i = 0; i < 10; i++) {
    		CurveArray[i] = 0;
    	}
    	Invalidate();
    	ValCount = 0;
    }
    
    void CDialogGraph::OnButtonConfig() 
    {
    //removed: content of this function
    }
    
    
    LRESULT CDialogGraph::OnReceiveVal(WPARAM wParam, LPARAM lParam)
    {
    //removed: contents of this function
    	return 0L;
    }
    
    void CDialogGraph::OnSize(UINT nType, int cx, int cy) 
    {
    	TRACE("\r\nIN: CDialogGraph::OnSize    cx = %d, cy = %d", cx, cy); 
    	CDialog::OnSize(nType, cx, cy);
    	// TODO: Code für die Behandlungsroutine für Nachrichten hier einfügen
    	CRect m_rcGraphSize;
    	CPoint oben_links, unten_rechts;
    	GetClientRect(m_rcGraphSize);
    
    	unten_rechts = m_rcGraphSize.BottomRight();
    	unten_rechts.x = unten_rechts.x-100;
    	oben_links.y = 2;		//just a small space to the border
    	oben_links.x = 100;		//on the left we have the buttons
    	unten_rechts = m_rcGraphSize.BottomRight();
    	unten_rechts.x -= 2;	//Again just a small space to the border
    	unten_rechts.y -= 2;
    	m_rcGraphSize.SetRect(oben_links, unten_rechts);//m_rcGraphSize.BottomRight()); 
    	m_Graph.DestroyWindow();
    	if (!::IsWindow(m_Graph.m_hWnd)){
    		m_Graph.Create("XGraph","", WS_CHILD | WS_VISIBLE, m_rcGraphSize, this, 1001);
    		}
    //	Sleep(500);
    	//m_Graph.OnPrOnProperties();
    	TRACE("\r\nOUT: OnSize");
    }
    
    
    void CDialogGraph::OnButtonClearGraph() 
    {
    	TRACE("\r\nIN: OnClearGraph");
    	OnButtonStop();
    	LoescheGrafik();
    	TRACE("\r\nOUT: OnClearGraph");
    }
    
    void CDialogGraph::OnCancel() 
    {
    	TRACE("\r\nIN: CDialogGraph::OnCancel");
    	int i = 10;//We reset the communication telegrams back to normal operation:
    	
    	TRACE("\r\n11");
    	OnButtonStop();
    	WillGraphVerlassen = true;
    	Sleep(200);
    	while((!GraphVerlassenOK) && (i > 0))	{
    		i--;
    		TRACE("\r\ni = %d", i);
    		Sleep(50);
    	}
    	TRACE("\r\n12");
    	LoescheGrafik();
    	Sleep(200);
    	TRACE("\r\n13");
    //	HwndGraphDlg = 0;
    	TRACE("\r\n14");
    	Sleep(200);
    	TRACE("\r\n15");
    //	m_Graph.DestroyWindow();
    //	MessageBox("3");
    	i = 10;
    	while(i > 0)	{
    		i--;
    		TRACE("\r\ni = %d", i);
    		Sleep(50);
    	}
    	TRACE("\r\n16");
    	
    	TRACE("\r\nOUT: CDialogGraph::OnCancel");
    	CDialog::OnCancel();
    }


    [Andreas]: Added code tags...
    Last edited by Andreas Masur; August 28th, 2003 at 04:42 AM.

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

  3. #3
    Join Date
    Aug 2001
    Location
    Sydney, Australia
    Posts
    813
    use rational purifier, thats always good
    Microsoft LVP - Least Valuable Professional

    Please rate this post... Pleeeeeeaaassee!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured