Error in memory location at "0x00000000"

TeeChart for ActiveX, COM and ASP
Post Reply
Hari
Newbie
Newbie
Posts: 12
Joined: Wed Jun 09, 2010 12:00 am

Error in memory location at "0x00000000"

Post by Hari » Mon Jul 12, 2010 7:46 pm

I am using Activex version of TeeChart to plot a few charts with the data taken from a text file. I am using "fopen" and "fgets" functions to read the data and i am storing them in a safe array (similar method as given in "add data arrays" example for Visual C++). I am getting the following error (4 out of 5 times) when i close my application/dialog box.

The instruction at "0x00000000" referenced memory at "0x00000000". The memory could not be "read". Click on OK to terminate the program.


Following are some of the features in my program:

* i have to plot 7 different charts (one in each dialog box) with the data taken from 6 different text files. All the 7 charts have to be displayed in parallel and hence i am using the "modeless" method

* i am calling the main dialog box from "InitInstance" function using "DoModal()" and then i am creating objects for other dialog boxes inside the main dialog box. The code looks something like this:-

Code: Select all

BOOL CTest2App::InitInstance()
{
	AfxEnableControlContainer();
#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif
	nbiq_dialog1 nbiq_dlg1;
	m_pMainWnd = &nbiq_dlg1;
	int nResponse = nbiq_dlg1.DoModal();
        return FALSE;
}

Code: Select all

BOOL nbiq_dialog1::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	PlotNBIQSpectrum();

	nbiq_dialog2 *nbiq_dlg2;
	nbiq_dlg2 = new nbiq_dialog2;
	nbiq_dlg2->Create(IDD_NBIQ_DIALOG1,this);
	nbiq_dlg2->ShowWindow(1);

	return TRUE;  // return TRUE  unless you set the focus to a control
}
IDD_NBIQ_DIALOG1 is the main dialog box and i am creating object for the next dialog box (nbiq_dialog2) inside the OnInitDialog() of "nbiq_dialog1"

* i am using "COleSafeArray" data type and "AddArray" function to plot the line charts. I then use the "clear" function of "COleSafeArray" class at the end of each file to clear the contents

Can someone throw some light on this issue? I have been facing this problem over past 1 week and i am not able to trace the problem.

PS: i am a newbie to C++ and MFCs. I have learned to do all this only by looking at example projects and by going through this forum.


Thanks,
Hari

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Error in memory location at "0x00000000"

Post by Yeray » Tue Jul 13, 2010 2:49 pm

Hi Hari,

Thank you for your explanations and for taking the time to search around this forum to acquire some experience.
However, if I understood well, you are experiencing problems with a quite big and complex application. So I'd recommend you to try to simplify it as much as possible so you can send it to us and we can understand and debug it to find what may be causing the problem asap.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Hari
Newbie
Newbie
Posts: 12
Joined: Wed Jun 09, 2010 12:00 am

Re: Error in memory location at "0x00000000"

Post by Hari » Tue Jul 13, 2010 6:46 pm

Hi Yeray.

I am using COleSafeArray to store the data for all my charts and i guess this is causing some problem. Even though i am using the "COleSafeArray::Destroy()" at the end, the memory is not cleared and this might be causing the memory issue. It would be great if you can throw some light on the usage of SafeArrays. As mentioned earlier, i am using the method given in the "add data arrays" example.

Or can you suggest some other way to use CSeries::AddArray()? My objective is to plot a simple line chart with the X and Y values available in a text file. However the length of the data is in the order of 250,000 and they are of type FLOAT.

SeriesTextSource is not an option for me since i need to read the text file and remove some header information before plotting it. Hence i am using fopen() and fread() to manipulate the data.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Error in memory location at "0x00000000"

Post by Narcís » Wed Jul 14, 2010 9:23 am

Hi Hari,
I am using COleSafeArray to store the data for all my charts and i guess this is causing some problem. Even though i am using the "COleSafeArray::Destroy()" at the end, the memory is not cleared and this might be causing the memory issue. It would be great if you can throw some light on the usage of SafeArrays. As mentioned earlier, i am using the method given in the "add data arrays" example.
Have you seen the exampe at C:\Program Files\Steema Software\TeeChart Pro v8 ActiveX Control\Examples\Visual C++\Version 6\Add data arrays?
Or can you suggest some other way to use CSeries::AddArray()? My objective is to plot a simple line chart with the X and Y values available in a text file. However the length of the data is in the order of 250,000 and they are of type FLOAT.
250.000 floats in a series shouldn't be a problem.
SeriesTextSource is not an option for me since i need to read the text file and remove some header information before plotting it. Hence i am using fopen() and fread() to manipulate the data.
With SeriesTextSource you can use SetHeaderLines property to exclude header lines.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Hari
Newbie
Newbie
Posts: 12
Joined: Wed Jun 09, 2010 12:00 am

Re: Error in memory location at "0x00000000"

Post by Hari » Wed Jul 14, 2010 5:17 pm

Have you seen the exampe at C:\Program Files\Steema Software\TeeChart Pro v8 ActiveX Control\Examples\Visual C++\Version 6\Add data arrays?
I am using the similar method as given in the example. I am repeating the example code 7 times to plot 7 different charts. In spite of that, i am getting the above mentioned error.

Can you suggest some other way to use CSeries::AddArray() without using COleSafeArrays?

Thanks,
Hari

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Error in memory location at "0x00000000"

Post by Yeray » Thu Jul 22, 2010 11:57 am

Hi Hari,

Excuse us for the delayed reply.
Could you please try setting AutoRepaint to false before calling AddArray (or before the for where you call it) and set it back to true after adding the values?
We saw some cases in the past where this solved a similar problem.
Another option would be looping you array and add you values one by one with AddXY or AddXYZ method (also setting AutoRepaint to false before the AddXY loop, and setting it to true after it)
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Hari
Newbie
Newbie
Posts: 12
Joined: Wed Jun 09, 2010 12:00 am

Re: Error in memory location at "0x00000000"

Post by Hari » Thu Jul 22, 2010 5:28 pm

Hi Yeray.

I will try setting AutoRepaint to false and check if it solves the problem.
Another option would be looping you array and add you values one by one with AddXY or AddXYZ method
I tried AddXY but the program becomes very slow since i have more than 250,000 values in each plot and i am plotting atleast 3 such plots.

I am thinking that this problem might also occur due to the fact that i am creating multiple modeless dialog boxes (one for each chart). I might not be destroying the windows properly during exit. I am looking into both the areas.

Thanks,
Hari

Hari
Newbie
Newbie
Posts: 12
Joined: Wed Jun 09, 2010 12:00 am

Re: Error in memory location at "0x00000000"

Post by Hari » Thu Jul 22, 2010 6:14 pm

Hi Yeray.

I tried setting AutoRepaint to false before AddArray and setting it true again. However the problem still persists.

Along with the error in memory location "0x00000000", i am also getting the error:

Debug assertion failed!
Program: c:\proj\test.exe
File: cmdtarg.cpp
Line: 52


I am guessing this error is more due to multiple modeless dialogs. If you have any solution regarding this, it would be most helpful.

Thanks,
Hari

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Error in memory location at "0x00000000"

Post by Yeray » Thu Jul 22, 2010 6:19 pm

Hi Hari,
Hari wrote:I tried AddXY but the program becomes very slow since i have more than 250,000 values in each plot and i am plotting atleast 3 such plots.
Note that in a few words, the AddArray method deactivates the AutoRepaint, loops into the array and calls the Add method:

Code: Select all

Function TChartSeries.AddArray(Const Values:Array of TChartValue):Integer;
var t : Integer;
begin
  BeginUpdate;
  try
    result:=High(Values)-Low(Values)+1;
    for t:=Low(Values) to High(Values) do Add(Values[t]);
  finally
    EndUpdate;
  end;
end;
So to deactivate the AutoRepaint when you are going to add many points is usually very recommended.
Please, try if doing it solves the memory error.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply