Out of Memory error checking color of points

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
JayG
Newbie
Newbie
Posts: 71
Joined: Mon Sep 04, 2006 12:00 am

Out of Memory error checking color of points

Post by JayG » Fri Jul 09, 2010 4:22 pm

VBExpress 2008
TeeChart 4.0.2010.27962

I am working with a chart that has 117 line series with 24480 points each. In the BeforeDrawSeries Event, I have code which uses a for...next loop to loop through the points of a few of the series. When the following If statement executes, I get an Out Of Memory exception after about 6000 to 7000 points:

Code: Select all

If TChart1.Series(WhichSeries).Item(WhichSegment - 1).Color <> Color.Transparent And TChart1.Series(WhichSeries).Item(WhichSegment).Color <> Color.Transparent Then
    'Other stuff
End If
Here is the stack trace:
System.OutOfMemoryException was unhandled
Message="Exception of type 'System.OutOfMemoryException' was thrown."
Source="mscorlib"
StackTrace:
at System.Collections.ArrayList..ctor(Int32 capacity)
at Steema.TeeChart.Styles.ColorList..ctor(Int32 capacity, String name)
at Steema.TeeChart.Styles.ColorList..ctor(Int32 capacity)
at Steema.TeeChart.Styles.Series.get_Colors()
at Steema.TeeChart.Styles.SeriesPoint.get_Color()
at Flocis_Visualizer.ChartForm.TChart1_BeforeDrawSeries(Object sender, Graphics3D g) in C:\Documents and Settings\jay\My Documents\Visual Studio 2008\Projects\Flocis Visualizer\Flocis Visualizer\ChartForm.vb:line 1343
at Steema.TeeChart.TChart.Steema.TeeChart.IChart.DoBeforeDrawSeries()
at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools)
at Steema.TeeChart.Chart.InternalDraw(Graphics g)
at Steema.TeeChart.TChart.Draw(Graphics g)
at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Flocis_Visualizer.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


If I tell VB to continue, it will run through several thousand more points, then give the same error again.
It happens during the first drawing of the chart after all the series are added with their Visible properties set to false.
The error does not occur with the same number of series but fewer points (about 13000).

Is there any way to figure out if this is a TeeChart problem/bug or if VB is really running out of memory?

Jay

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Out of Memory error checking color of points

Post by Sandra » Mon Jul 12, 2010 11:06 am

Hello JayG,

I have made a simple project that here works fine.

Code: Select all

  public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.AutoRepaint = false;
           
            for (int i = 0; i < 117; i++)
            {
                Steema.TeeChart.Styles.FastLine line = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
                line.DrawAllPoints = false;
                tChart1[0].FillSampleValues(24480);
                
            }
            tChart1.AutoRepaint = true;
            tChart1.Refresh();
            tChart1.BeforeDrawSeries += new Steema.TeeChart.PaintChartEventHandler(tChart1_BeforeDrawSeries);

        }

        void tChart1_BeforeDrawSeries(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            tChart1.AutoRepaint = false;
            for (int i = 0; i < tChart1.Series.Count; ++i)
            {
                for (int j = 1; j < tChart1[i].Count; ++j)
                {
                    if (tChart1[i].IsNull(j-1) && tChart1[i].IsNull(j))
                    {
                    }
                }
            }

            tChart1.AutoRepaint = true;
            tChart1.Refresh();
        }
Please, you could modify previous code because, we can reproduce your problem and we could help you optimize code. If you prefer you could send us an example attaching it in its post.

Thanks,
Best Regards,
Sandra Pazos / 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

JayG
Newbie
Newbie
Posts: 71
Joined: Mon Sep 04, 2006 12:00 am

Re: Out of Memory error checking color of points

Post by JayG » Tue Jul 13, 2010 6:18 pm

Hi Sandra,

Thanks for the suggesion. When I changed my code from checking for not Color.Transparent to checking for not IsNull, the error went away.

I'm nut sure why I was checking the color of the point instead of checking for a null value. I originally wrote the code a long time ago when I was fairly new to TeeChart, so maybe I didn't realize I could use the IsNull method at the time.

Also, I modified your code to make it more like my original code and converted it to VB:

Code: Select all

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeChart()
    End Sub

    Sub InitializeChart()
        Dim i As Integer
        Dim line As Steema.TeeChart.Styles.Line

        TChart1.Aspect.View3D = False
        TChart1.AutoRepaint = False

        For i = 0 To 116
            line = New Steema.TeeChart.Styles.Line(TChart1.Chart)
            line.Visible = False
            TChart1(i).FillSampleValues(24480)
        Next i
        TChart1.AutoRepaint = True
        TChart1.Refresh()
    End Sub

    Private Sub TChart1_BeforeDrawSeries(ByVal sender As System.Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.BeforeDrawSeries
        Dim i As Integer
        Dim j As Integer

        TChart1.AutoRepaint = False
        For i = 0 To 5
            For j = 1 To TChart1(i).Count - 1
                If  TChart1.Series(i).Item(j - 1).Color <> Color.Transparent And TChart1.Series(i).Item(j).Color <> Color.Transparent Then
                    'stuff
                End If
            Next j
        Next i
        TChart1.AutoRepaint = True
    End Sub
It ran fine with no error (although much slower), so I'm not sure what else may be causing the error in my full application. One difference is that in my application, the data for all the series is from a table in an ADO DataSet using the .DataSource and related properties. Of course there is a lot of other code also, so there are many differences, but I don't have time to find the specific cause since it is working with the IsNull method.

Jay

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Out of Memory error checking color of points

Post by Sandra » Wed Jul 14, 2010 11:12 am

Hello Jay,

Could you say please if next code works as you want and solve your problem?

Code: Select all

  Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        InitializeChart()
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub InitializeChart()
        TChart1.Aspect.View3D = False
        TChart1.AutoRepaint = False
        Dim i As Integer
        Dim line As Steema.TeeChart.Styles.FastLine
        TChart1.Aspect.View3D = False
        TChart1.AutoRepaint = False
        For i = 0 To 116
            line = New Steema.TeeChart.Styles.FastLine(TChart1.Chart)
            line.DrawAllPoints = False
            TChart1(i).FillSampleValues(24480)
        Next
        TChart1.AutoRepaint = True
        TChart1.Refresh()
        AddHandler TChart1.BeforeDrawSeries, AddressOf Me.TChart1_BeforeDrawSeries
    End Sub

    Private Sub TChart1_BeforeDrawSeries(ByVal sender As System.Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        TChart1.AutoRepaint = False
        Dim i, j As Integer
        For i = 0 To 5
            For j = 1 To TChart1(i).Count - 1
                If (TChart1(i).IsNull(j - 1) And TChart1(i).IsNull(j)) Then

                End If

            Next
        Next
        TChart1.AutoRepaint = True
        TChart1.Refresh()
    End Sub
Thanks,
Best Regards,
Sandra Pazos / 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

JayG
Newbie
Newbie
Posts: 71
Joined: Mon Sep 04, 2006 12:00 am

Re: Out of Memory error checking color of points

Post by JayG » Wed Jul 14, 2010 3:01 pm

Sandra,

Checking for a null value instead of checking the color in my full application did solve my problem. Everything is working as I want it to now.

I just posted that other code to let you know that checking the color and checking for a null value both worked when used in a simple test application.

Jay

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Out of Memory error checking color of points

Post by Sandra » Thu Jul 15, 2010 9:50 am

Hello Jay,

Ok, thanks for your information.


Thanks,
Best Regards,
Sandra Pazos / 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

Post Reply