Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Tools for Windows
 Charting and Real-Time Graphics Tools for Windows
 WGRedrawGraph
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kontraband

8 Posts

Posted - 17 Aug 2007 :  10:25:43  Show Profile  Reply with Quote
Hello

I have a problem with an access violation when redrawing a graph. I've read that when using the WGReconnectDataSet old datasets should be deleted after the new ones are connected. It works a couple of times to redraw the graph but suddenly I get the 'unhandled exception in xxxx.exe (WCT32DR3.DLL): 0xC0000005: Access Violation'.

I'm using Revision 3.0 / WINBMC100 and vc++ 6.0.

The call stack says:

WCT32DR3! 10008012()
WCT32DR3! 1002d835()
QCGraphWnd::WGRedrawGraph(int 1) line 968
CGrafPicGraph::RegenerateGraph() line 534

If I dont remove the old datasets no access violation occurs but then there will be a memory leak instead. Unfortunatly I can't see whats in the QCGraphWnd::WGRedrawGraph so I would be very greateful if someone could give me some ideas of what could be the problem with this implementation.




The chart has a history function so it will be redrawn when the user uses the mousewheel.

The CGrapfPicGraph is derived from QCGraphWnd.
I've removed some lines

BOOL CGrafPicGraph::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
//some axis formating
..
..

WGChangeAxisRange( m_hXAxis, m_rLeft, m_rRight);
WGChangeAxisScale( m_hXAxis, ST_LINEAR );
WGChangeAxisTicks( m_hXAxis, rTickSpaceX, nTick, POS_BELOW );

RegenerateGraph() ;
return 0 ;
}

BOOL CGrafPicGraph::RegenerateGraph()
{
m_csLock.Lock();
BOOL bResult = m_pDoc->UpdateAllDataSets( this ) ;
PGRAPH_DEF pGD = (this)->GetGraphDesc() ;

for (int i=0;i<m_pDoc->m_nNumPlots;i++)
{
::WGReconnectDataSet ( pGD, m_pDoc->m_sPlotRecord[i].m_hPlot, m_pDoc->m_sPlotRecord[i].m_pDataSet->GetHandle() ) ;
}

m_pDoc->DeleteOldDataSets(); // deletes datasets that we dont need anymore since they've been replaced
WGRedrawGraph(TRUE); // this is line 534

m_csLock.Unlock();
return bResult ;
}


BOOL CGrafPicDoc::UpdateAllDataSets( CGrafPicGraph* pGraph )
{
QCStaticData * pDataSetNew = NULL ;
BOOL bSuccess = TRUE ;

for (int i=0;i<m_nNumPlots;i++)
{

pDataSetNew = m_sPlotRecord[i].BuildDataSet (
m_tStart,
m_fXStart,
m_fXAxisLength,
(int) m_fXAxisLength,
m_bLog
); // will return pDataSet = new QCStaticData ( NULL, m_px1, m_py1, nNumPoints, m_nGroupSize);

//add the new dataset to storage for removal when not used anymore
m_DataListArray[m_nCurrentDataList]->Add(pDataSetNew);

if (m_sPlotRecord[i].m_hPlot)
m_sPlotRecord[i].SetDataSet( pDataSetNew ) ;
else
m_sPlotRecord[i].SetDataSet( (QCStaticData *) NULL ) ;

if (!pDataSetNew)
bSuccess = FALSE ;

pDataSetNew = NULL ;
}
return bSuccess ;
}


void CGrafPicGraph::BuildGraph()
{
int i ;
WGSetPlotArea( 0.1, 0.1, 0.82, 0.90, C_LIGHTGRAY) ;
WGChangePlotBackgnd (GetSysColor(COLOR_BTNFACE));
WGSetLineStyle(PS_SOLID, 1, C_BLACK);
WGSetTextByName(C_BLACK, "Arial", 8, TEXT_NORMAL);

// linear or logarithmic scaling
if (m_pDoc->m_bLog)
WGSetAxesScale (ST_LINEAR, ST_LOG);
else
WGSetAxesScale (ST_LINEAR, ST_LINEAR);

WGAutoAxes(m_pDoc->m_sPlotRecord[0].m_pDataSet, AS_ROUNDCLOSE, INTF_MAXMIN, &m_hXAxis, &m_hYAxis) ;

realtype rXMin, rXMax, rXInt, rYMin, rYMax, rYInt, rXShadeMin ;
COLORREF cShadeColor = GetSysColor(COLOR_BTNFACE) ;
cShadeColor;
int color [3];
color[0] = GetRValue(GetSysColor(COLOR_BTNFACE));
color[1] = GetGValue(GetSysColor(COLOR_BTNFACE));
color[2] = GetBValue(GetSysColor(COLOR_BTNFACE));
WGGetAxisRange ( m_hXAxis, &rXMin, &rXMax, &rXInt ) ;
WGGetAxisRange ( m_hYAxis, &rYMin, &rYMax, &rYInt ) ;
WGSetTextByName( C_BLACK, "Arial", 8, TEXT_NORMAL );



// set line color and line style for every plot
for (i=0;i<m_pDoc->m_nNumPlots;i++)
{
// set line style of plot, with spline interpolation
WGSetLineStyle(m_pDoc->m_sPlotRecord[i].m_nLineStyle, m_pDoc->m_sPlotRecord[i].m_nThickness, C_BLACK);
m_pDoc->m_sPlotRecord[i].m_hPlot = WGLinePlot(m_pDoc->m_sPlotRecord[i].m_pDataSet, FALSE, FALSE);
// change color to RGB COLORREF
WGChangeLineColorRGB ( m_pDoc->m_sPlotRecord[i].m_hPlot, m_pDoc->m_sPlotRecord[i].m_crColor, 0 ) ;
}
}


quinncurtis

1164 Posts

Posted - 17 Aug 2007 :  13:43:48  Show Profile  Reply with Quote
There is nothing that tell based on the code that you show. Invariably the problem is always in the code you don't show. I would guess that you are introducing null pointers into the datasets.

If the exception only occurs when you free the datasets, then I would suspect that code, which you don't show.

When you create new datasets, are you allocating new pointers each time, or are you trying to re-use previously allocated pointers?
Go to Top of Page

kontraband

8 Posts

Posted - 22 Aug 2007 :  05:07:09  Show Profile  Reply with Quote
I think I've found the source.. the responsible programmer did not follow your guidelines that a new dataset should be created first, then reconnected and the old dataset should then be deleted. Of what I can tell the old dataset was deleted first and the new dataset used the same arrays as the previous dataset somehow causing the dataset handles to be the same. This seemed to work ok with some occasional crashes untill I changed the code so that the old dataset was deleted after WGReconnect. Since the dataset handles was the same the newly created dataset was freed after the WGReconnect so when the graph was redrawn I got some Access Violation. Now I'm allocating new arrays for each dataset and deallocating them when they turn old. So far it seem to work. I guess this is also the source for my earlier posts on the forum. Thank you for taking the time to answer my questions.

Peace!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Quinn-Curtis Forums © 2000-07 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07