App kept crashing with access violation!!!!

TeeChart for ActiveX, COM and ASP
Post Reply
David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

App kept crashing with access violation!!!!

Post by David » Thu Nov 23, 2006 3:41 am

Hi,

The chart kept popping up dialog box saying access violation in some address. This problem happens in some PCs, but not in all. Is it related with how I distribute the ActiveX control?

I used AddXY to add some data for a scLine series, then the error occurs.

Thanks a lot.
David
Last edited by David on Mon Dec 04, 2006 7:15 am, edited 1 time in total.

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Thu Nov 23, 2006 7:42 am

Hi, Narcís and Pep,

I send an email to both of you with a demo project that can reproduce the problem. Hopefully it can be solved asap. Please keep me updated with any result.

Thank you very much!
David

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Tue Nov 28, 2006 10:48 am

Hi,

I also tried AddArray for both scFastLine and scLine. The problem remains. It is really urgent. Would you please let me know if there is any info?

Thanks a lot.

David

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Mon Dec 04, 2006 1:01 am

Hello? Please, it has been about two weeks but no one replied. Would anyone please help? My project deadline is very close now.

David

John P. Francis
Newbie
Newbie
Posts: 15
Joined: Mon Jun 26, 2006 12:00 am
Location: San Diego, Ca.

ActiveX Memory Error

Post by John P. Francis » Mon Dec 04, 2006 9:16 pm

Had the same problem, mainly with large ( greater than 20,000 data points). Two parts, first is you need to use AddArray plus make the allocation larger than you need for the ole-safe-array. Second, so that the chart-ocx can handle the large array, fill the array with random data when you initialize, so when you give it the real data-array the chart has already sized itself internally. I also wrote some exception handlers to when using large data sets. Hope this helps.

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Tue Dec 05, 2006 1:07 am

Hi, John,

Thanks for your info. Would you please tell me how to allocate larger array for the AddArray? When you fill the array with random data, will it appear in the display? Also, I am not familiar with the exception handling. It would be greatly appreciated if you could give me some brief knowledge.

Thanks a lot.
David

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Tue Dec 05, 2006 9:21 am

Hello David,

We have run extensive tests with the sample project you sent and unfortunately haven't yet been able to find the cause of the error, or even exactly how it is occurring. John's suggestion to use AddArray with memory allocation is worthwhile trying as in initial tests here, when that technique is included, are positive (ie. we haven't been able to provoke the error). Thanks for the input John.

ie (syntax similar to TeeChart's VC++AddArray demo)

Code: Select all

void CFHTesterDlg::AssignData1(double &dInitIndex)
{
  int nDataNum = 5000;
  double dSum = 0.0;
  int nFirst = 0;
  double dX = 0.0;

  COleSafeArray XValues;
  COleSafeArray YValues;
  DWORD numElements[] = {200000};

  // Create the safe-arrays...
  XValues.Create(VT_R8, 1, numElements);
  YValues.Create(VT_R8, 1, numElements);

  for(long i = 0;i<nDataNum;i++)
  {
	dSum = rand();
	dX = dInitIndex + i + 1;
		
	XValues.PutElement(&i, &dX);
	YValues.PutElement(&i, &dSum);
  }
         
  // Add arrays
  m_chart1.Series(0).AddArray( nDataNum,YValues,XValues);

  dInitIndex = m_chart1.Series(0).GetXValues().GetMaximum();
}
Regards,
Marc
Last edited by Marc on Tue Dec 05, 2006 12:59 pm, edited 1 time in total.
Steema Support

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Tue Dec 05, 2006 11:07 am

Hi,

However, when I increase the sereis number to 6 which is the real case in my app, the error appears again. :-(

More help greatly needed!

Thanks a lot!
David

John P. Francis
Newbie
Newbie
Posts: 15
Joined: Mon Jun 26, 2006 12:00 am
Location: San Diego, Ca.

Increasing the Size of a safe Array & Exception Handling

Post by John P. Francis » Tue Dec 05, 2006 5:24 pm

// Code Snipit for increasing
COleSafeArray XValues;
COleSafeArray YValues;
long MaxPlotPoints;[/code]
...
// Initial Creating, somewhere in init_foo()
XValues.Create(VT_R8, 1, &MaxPlotPoints );
YValues.Create(VT_R8, 1, &MaxPlotPoints );
...
// Resize function
BOOL CMojoClass::CheckSafeArraySize(void)
{
BOOL resize = FALSE;

long tmpSize = MaxPlotPoints;
long CellCntEst = (long)CellArrayClnt.Count(); // get the size

if( MaxPlotPoints < CellCntEst )
{
if( CellCntEst > 25000 )
MaxPlotPoints = 50000;
if( CellCntEst > 50000 )
MaxPlotPoints = 75000;
if( CellCntEst > 75000 )
MaxPlotPoints = 100000;
if( CellCntEst > 100000 )
MaxPlotPoints = 150000;
if( CellCntEst > 150000 )
MaxPlotPoints = 200000;
if( CellCntEst > 200000 )
MaxPlotPoints = 250000;
if( CellCntEst > 250000 )
MaxPlotPoints = 500000;
if( CellCntEst > 500000 )
MaxPlotPoints = 750000;
if( CellCntEst > 750000 )
MaxPlotPoints = 1000000;

resize = TRUE;
}

if( TRUE == resize )
{
SAFEARRAYBOUND sbArray[1];
//long uBound; // upper-bound, last index value
//long lBound; // lower-bound, usually zero
sbArray[0].cElements = MaxPlotPoints+1;// uBound;
sbArray[0].lLbound = 0;// lBound;
XValues.Redim( sbArray );
YValues.Redim( sbArray );

#ifdef _DEBUG
TRACE("Resized SafeArrays; from:%lu to: %lu \n", tmpSize, MaxPlotPoints );
#endif
}

return resize;
}


//.. exception handling when the ocx takes a shit
//| Try and handle the coloring, sometimes to fast for the Ole-Interface
TRY
{
//| Color the Data-Point
m_pChart->Series(ActiveSeriesIdx).SetPointColor(idx, PointColor);
}
CATCH( COleDispatchException, e )
{
// AfxMessageBox ("ColorEvents: Ole Exception Called!", NULL, MB_OK );
ReColorEvents = TRUE;
break;
}
END_CATCH

//.. I pass the ReColorEvents flag up on level and then try again,
//.. usually the TeeChart ocx has ajusted its memory by then and I
//.. can continue to color the plotted points.

//.. I'm not able to reproduct this in a non-dialog based app. So I'm trimming down my app to send to steema as an example of both heap errors and exceptions thrown by the ocx. Hopefully by the end of the day.

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Wed Dec 06, 2006 1:00 am

Hi, John,

Thank you so much! I will look through the code and hopefully it will solve my problem. I just have one question. In my app, when the access violation occurs, the ocx stops updating, which means no new data can be plotted. With this exception handling, will it be able to update again?

Thanks a lot!
David

John P. Francis
Newbie
Newbie
Posts: 15
Joined: Mon Jun 26, 2006 12:00 am
Location: San Diego, Ca.

Update after Exception

Post by John P. Francis » Mon Dec 11, 2006 7:57 pm

Yes, things should be ok ...

But If the OleSafeArray is the problem, maybe not. I've not really found any really good info on OleSafeArray, but where it is created and updated, ie scope and thread, is very important. I usually keep it within the process and I do not pass it around.

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Fri Dec 15, 2006 9:03 am

Hi,

It seems the problem remains unkilled here. So is there any good news with the bug hunting? Is it possible that you could fix it by the end of this year? If not, I would have to remove it from my app and try some other way to display data, which is the last thing I would like to do. So although it is Christmas time, do please help me solve it sooner and keep me updated.

Merry X'mas to all!
David

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Mon Dec 18, 2006 12:52 pm

Hello David,

We still don't have a definitive cause identified for this issue. It's related to threads and paint process. It may be that the thread created on the existing Chart interferes with the standard repaint cycle of that Chart. If the creation of the entire Chart were to lie within the thread cycle the issue may not occur. To try to negate that behaviour we can set AutoRepaint to false and repaint the Chart only on demand.

Eg.

Code: Select all

void CFHTesterDlg::Chart1Init()
{
  m_chart1.SetAutoRepaint(false);
//....other initialisation routines...
}
and...

Code: Select all

void CFHTesterDlg::AssignData1(double &dInitIndex)
{
//....add data routine....
// then:	
  m_chart1.SetAutoRepaint(true);
  m_chart1.Repaint();
  m_chart1.SetAutoRepaint(false);	
}
Another clue to the paintcycle/thread hypothesis is that the Chart in tests was reacting badly to a mouseover whilst the data is being loaded. With AutoRepaint false it has been behaving correctly. That would need to be applied to all Charts being data-loaded in this way.

I hope that may be of help.
Regards,
Marc
Steema Support

David
Advanced
Posts: 203
Joined: Tue Nov 08, 2005 5:00 am

Post by David » Tue Dec 19, 2006 2:23 am

Hi, Marc,

I tried your method and it does help, but unfortunately, it didn't solve it. I removed the finite time repaint in the thread so that the repaint would continue until I click the stop button. It seemed with your method, the app can run correctly most of the time, but the erro would still occur sometimes. I also tried adding some delay before assign data, still the same problem.

With this kind of problem, we can't deliver to our customer. I do appreciate the help from you and other teechart staffs, but I have to consider some other way to display the data. I just hope you could solve this problem as soon as possible so that I will still be able to use it in my future projects. Please keep me updated.

Thanks a lot and merry Christmas!
David

Post Reply