|
runtime error R6025, in MFC SDI project |
Posted by James on Feb-04-2021 11:32 |
|
Hi,
I'm trying to draw a chart in SDI's view area.
First I create a ChartViewer container at the xxxView OnCreate time.
Then I refer the financedemo code, and put it on xxxView's OnDraw function, it works fine, but the chart can't be updated anymore.
After run the realtimedemo, I supose that changing a chart may use the 'updateViewPort' method to replace the 'setChart'.
So I add the updateViewPortOnViewPortChangeddrawChart mechanism in SDI frame ( m_chartView is a Static window of xxxView and also its child). The chart has been completed, but, there is an error of R6025.
By tracking the code, I got that the error occures at line 929 of ChartViewer.cpp:
setChartMetrics((0 != c) ? c->getChartMetrics() : 0);
e.g. the c->getChartMetrics() routine.
Thanks in advance
Regards
James
DongFang_Data_AnalyseView.cpp |
---|
|
| |
Re: runtime error R6025, in MFC SDI project |
Posted by James on Feb-04-2021 14:21 |
|
Hi,
New information:
1. the normal chart like XYchartPieChart can work normally except the Financechart.
2. the Financechart works fine if code in the OnDraw function of xxxView --- but the chart can't be updated anymore.
Thanks
James |
Re: runtime error R6025, in MFC SDI project |
Posted by Peter Kwan on Feb-05-2021 01:02 |
|
Hi James,
In your code, you delete the chart after displaying it, like:
viewer->setChart(c);
delete c;
Then later your code trigger the ViewPortChanged event. This event needs to obtain the "ViewPort" (the plotarea) of the chart object, but the chart object has already been deleted. This causes the program to crash.
In all our sample code, if the ViewPortChanged event is used, the chart object that is displayed is not deleted immediately. The code is like:
// Delete the previous chart in the CChartViewer
delete viewer->getChart();
// Set a new chart to the CChartViewer. Do not delete the chart until the next chart
// is available to replace it.
viewer->setChart(c);
Also, we add a line "delete viewer->getChart();" in the destructor of the CView to delete the last chart when the program shuts down.
Another issue is that it your code updates the control in OnDraw. The OnDraw is normally used to perform low level update to the screen pixels. If you want to draw the chart, you can draw it in OnInitialUpdate, like:
void CmfcsdidemoView::OnInitialUpdate()
{
CView::OnInitialUpdate();
DrawChart(&m_ChartViewer);
}
The OnDraw is called by MFC everything the screen changes. For example, if you resize the window, the OnDraw will be called many times as your drag the on the window border. It is not necessary to update the chart when the window is resized because the chart has not changed. Updating the controls in OnDraw will generate many unnecessary updates, and may cause performance problems or screen flickering.
You can update the chart by calling DrawChart. You can call it in OnViewPortChanged or in another method.
I also see you use "Sleep(10);" in your code to "wait for the chart to update". The code actually does the opposite. It prevents the chart to update, because it puts the drawing thread to sleep.
Hope this can help.
Regards
Peter Kwan |
Re: runtime error R6025, in MFC SDI project |
Posted by James on Feb-05-2021 09:48 |
|
Hi, Peter,
Thanks for your help.
Now the financechart works normally in MFC SDI's View.
The key code is :
delete viewer->getChart();
viewer->setChart(c);
Regards
James |
|