Exception: Index was outside the bounds of the array

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Mike Jones
Newbie
Newbie
Posts: 4
Joined: Thu Feb 01, 2007 12:00 am

Exception: Index was outside the bounds of the array

Post by Mike Jones » Thu May 15, 2008 4:46 pm

I can reproduce this by having a complex 2D chart that contains series made up of CustomPoints. It seems to occur when the chart is first rendering and the mouse is over the area where the chart is about to be drawn.

Looking at the source code for TeeChart.dll version 3.2.3016.15521, I find

Code: Select all

public override int Clicked(int x, int y)

    {
      if (chart != null) chart.graphics3D.Calculate2DPosition(ref x, ref y, StartZ);

      int result = base.Clicked(x, y);

      if ((result == -1) && (firstVisible > -1) && (lastVisible > -1))
        for (int t = firstVisible; t <= lastVisible; t++)
          if (ClickedPointer(t, CalcXPos(t), CalcYPos(t), x, y))
          {
            OnClickPointer(t, x, y);
            return t;
          }

      return result;
    }
The call to CalcXPos(t), where t =0 and lastVisible = 0;

I guess the thing that seems wrong here is why is a click event firing when I have not clicked on anything. It is clear by the call stack below that the series of method calls is initiated by a mouse over event. That appears to be a problem because it ends up calling a mouse click event that is not quite ready. I did verify that if I keep the mouse out of the area in which it is drawing, I do not get the exception.

Stack trace:

TeeChart.dll!Steema.TeeChart.Styles.ValueList.this[int].get(int index = 0) Line 515 + 0xd bytes C#
TeeChart.dll!Steema.TeeChart.Styles.Series.CalcXPos(int index = 0) Line 2792 + 0xe bytes C#
TeeChart.dll!Steema.TeeChart.Styles.CustomPoint.CalcXPos(int valueIndex = 0) Line 1329 + 0x9 bytes C#
TeeChart.dll!Steema.TeeChart.Styles.CustomPoint.Clicked(int x = 269, int y = 157) Line 1373 + 0x12 bytes C#
TeeChart.dll!Steema.TeeChart.Tools.MarksTip.FindClickedSeries(int x = 269, int y = 157, ref int index = -1) Line 157 + 0x33 bytes C#
> TeeChart.dll!Steema.TeeChart.Tools.MarksTip.MouseEvent(Steema.TeeChart.MouseEventKinds kind = Move, System.Windows.Forms.MouseEventArgs e = {X = 269 Y = 157 Button = None}, ref System.Windows.Forms.Cursor c = {[Cursor: Default]}) Line 203 + 0x25 bytes C#
TeeChart.dll!Steema.TeeChart.Chart.BroadcastMouseEvent(Steema.TeeChart.MouseEventKinds kind = Move, System.Windows.Forms.MouseEventArgs e = {X = 269 Y = 157 Button = None}, ref System.Windows.Forms.Cursor c = {[Cursor: Default]}) Line 1190 + 0x28 bytes C#
TeeChart.dll!Steema.TeeChart.Chart.BroadcastMouseEvent(Steema.TeeChart.MouseEventKinds kind = Move, System.Windows.Forms.MouseEventArgs e = {X = 269 Y = 157 Button = None}, System.Windows.Forms.Keys modKeys = None) Line 1174 + 0x12 bytes C#
TeeChart.dll!Steema.TeeChart.TChart.OnMouseMove(System.Windows.Forms.MouseEventArgs e = {X = 269 Y = 157 Button = None}) Line 1381 + 0x25 bytes C#

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

Found the root cause

Post by Mike Jones » Thu May 15, 2008 7:52 pm

Found that the problem is that I am adding MarksTip tool during initialization of the chart control. This causes a problem if the chart takes a significant amount of time to render. While rendering, if the user mouses over or clicks on the chart, it will consistently throw this exception. However, if I postpone the adding the MarksTip tool until the chart has rendered, I can't get the exception to occur.

2 possible ways to solve this bug, both should maybe implemented

1. Use the After Draw event and not add the MarksTip tool until this event fires or some other means to detect that the chart has completed rendering.

2. Put in some logic to double check the values before indexes are used. Look at the stack trace provided and determine the best place to put this check in. This would be a change to the TeeChart source. Might be good to put into place anyway. As an extra measure put a try/catch around accessing the Steema.TeeChart.Styles.ValuList.this.Get property.

Mike Jones
Advanced
Posts: 192
Joined: Thu Feb 01, 2007 12:00 am
Contact:

The real fix

Post by Mike Jones » Thu May 15, 2008 9:36 pm

I think I have really fixed the issue. After implementing solution #1, I still would see exceptions because on certain instances I would have a Series with 0 points. Because how we are using the TeeChart control, we will have series's with 0 points, sometimes. So I modified the source.

Here is the change I made:

Code: Select all


In Steema.TeeChart.Tools.MarksTip

private Styles.Series FindClickedSeries(int x, int y, ref int index)

    {
      
      for (int i = chart.Series.Count - 1; i >= 0; i--)	 
      {
          if (chart[i].Visible && chart.Series[i].Count > 0) 
        {
          index = chart.Series[i].Clicked(x, y);
          if (index != -1)
          {
            return chart.Series[i];
          }
        }
      }

      
      index = -1;
      return null;
    }
Noticed I added another condition to the if statement "&& chart.Series.Count > 0"

This seemed to fix my issue.

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

Post by Narcís » Thu May 22, 2008 1:40 pm

Hi Mike,

Thank you very much! It looks like a good fix to us. I've added it to the source code for the next maintenance release.
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

Sim
Newbie
Newbie
Posts: 11
Joined: Fri Oct 05, 2007 12:00 am

Post by Sim » Fri Aug 08, 2008 1:33 pm

Hi I am using TeeChart v3.5.3105.20151 for .Net which is I believe the latest version available. I am getting a very similar error to the one discussed in this thread by using the NearestTool on a series that gets its datasource (datatable) emptied:

Index was outside the bounds of the array.
at Steema.TeeChart.Styles.ValueList.get_Item(Int32 index)
at Steema.TeeChart.Styles.Series.CalcXPos(Int32 index)
at Steema.TeeChart.Styles.CustomPoint.CalcXPos(Int32 valueIndex)
at Steema.TeeChart.Tools.NearestPoint.PaintHint()
at Steema.TeeChart.Tools.NearestPoint.ChartEvent(EventArgs e)
at Steema.TeeChart.Chart.BroadcastToolEvent(EventArgs e)
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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


Is this a known issue or bug? Do you have an idea of what I can do to workaround the issue?

thanks!

Sim
Newbie
Newbie
Posts: 11
Joined: Fri Oct 05, 2007 12:00 am

Post by Sim » Fri Aug 08, 2008 1:51 pm

Hi, me again. I have created a small sample that reproduces the issue easily. I have uploaded the file to your upload page (http://www.steema.net/upload/Default.aspx).

The name of the file is NearestPointIssue.zip.

To reproduce the issue, do the following steps:
1- Drag your mouse over the chart so that the nearest point tool is used
2- Click on the button that I added at the top right corner of the chart to clear the poins in the line series.

You will see the exception right away.

Can you confirm that this is actually a bug and that it will be fixed in the next issue?

In the meantime, do you have a workaround for me?

Thanks!

Sim
Newbie
Newbie
Posts: 11
Joined: Fri Oct 05, 2007 12:00 am

Post by Sim » Mon Aug 11, 2008 1:28 pm

Hi guys, could you please confirm that you have received the attachment I sent friday regarding this issue?

Thanks.

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Aug 11, 2008 3:04 pm

Hello,
Sim wrote:Hi guys, could you please confirm that you have received the attachment I sent friday regarding this issue?
Yup, this defect has been entered into our bug-tracking software with reference TF02013322. It has already been fixed for the next maintenance release, due out in a few days.

A workaround could look like the following:

Code: Select all

		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			line1.FillSampleValues(20);
      tChart1.BeforeDraw += new Steema.TeeChart.PaintChartEventHandler(tChart1_BeforeDraw);
		}

    void tChart1_BeforeDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
    {
      if (line1.Count > 0)
      {
        nearestPoint1.Series = line1;
      }
      else
      {
        nearestPoint1.Series = null;
      }
    }

		private void button1_Click(object sender, EventArgs e)
		{
			line1.Clear();
		}
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

pw
Newbie
Newbie
Posts: 57
Joined: Fri Nov 15, 2002 12:00 am

Post by pw » Wed Aug 13, 2008 12:19 am

I've been having a similar problem, although it's very intermittent which makes pinpointing the cause very difficult for me.

However, the error message I received is:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Steema.TeeChart.Styles.ValueList.get_Item(Int32 index)
at Steema.TeeChart.Functions.CrossPoints.LinesCross(Int32 index1, Int32 index2, Double& x, Double& y)
at Steema.TeeChart.Functions.CrossPoints.DoCalculation(Series source, ValueList notMandatorySource)
at Steema.TeeChart.Functions.CrossPoints.AddPoints(Array source)
at Steema.TeeChart.Styles.Series.AddValues(Array source)
at Steema.TeeChart.Styles.Series.FillFromDataSource()
at Steema.TeeChart.Styles.Series.CheckDataSource()
at Steema.TeeChart.Styles.Series.set_Function(Function value)
at Analyst.frmInterconnectorView.InterconnectorChartPlot(String interconnectorName, DateTime startDate, DateTime toDate)
Any suggestions on what I should do? Thanks.

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Aug 13, 2008 8:26 am

Hello,
pw wrote:I've been having a similar problem, although it's very intermittent which makes pinpointing the cause very difficult for me.
Mmm, ok, I see what may be happening. Although I haven't been able to reproduce it, I've added the issue to our bug-tracking software with reference TF02013324 and a fix to it has been added to the next maintenance release, due out next month.

The only workaround I can think of would be to derive your own CrossPoints function and override DoCalculation, making it look like this:

Code: Select all

		protected override void DoCalculation(Styles.Series source, ValueList notMandatorySource)
		{
			if (Series.DataSourceArray().Count>1) 
			{
				source=(Series)(Series.DataSourceArray()[0]);
				tmp1=ValueList(source);
				tmpX1=notMandatorySource;
        Series tmpS=(Series)(Series.DataSourceArray()[1]);
        tmp2=ValueList(tmpS);
				tmpX2=tmpS.notMandatory;

				Series.Clear();

				if ((tmpX1.Count>1) && (tmpX2.Count>1)) 
				{
					int index1=0;
					int index2=0;

					double x,y;

					do 
					{
						if (LinesCross(index1,index2,out x,out y))
							Series.Add(x,y);

						if (tmpX2.Value[index2+1]<tmpX1.Value[index1+1])
							index2++;
						else
							index1++;

					} while ((index1 < (tmpX1.Count - 1)) && (index2 < (tmpX2.Count - 1)));	//TF02013324
				}
			}
		}
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

pw
Newbie
Newbie
Posts: 57
Joined: Fri Nov 15, 2002 12:00 am

Post by pw » Thu Aug 14, 2008 11:27 pm

Hi Christopher,

Can you please advise me on how I could apply the workaround in my code?

Code: Select all

Steema.TeeChart.Styles.Line flowDPLine = new Steema.TeeChart.Styles.Line(tChartInterconnector.Chart);                    
Steema.TeeChart.Styles.Line exportLimitDPLine = new Steema.TeeChart.Styles.Line(tChartInterconnector.Chart);
Steema.TeeChart.Styles.Line importLimitDPLine = new Steema.TeeChart.Styles.Line(tChartInterconnector.Chart);

Steema.TeeChart.Styles.Points exportPointDP = new Steema.TeeChart.Styles.Points(tChartInterconnector.Chart);
Steema.TeeChart.Styles.Points importPointDP = new Steema.TeeChart.Styles.Points(tChartInterconnector.Chart);
Steema.TeeChart.Functions.CrossPoints expCrossPointDP = new Steema.TeeChart.Functions.CrossPoints(tChartInterconnector.Chart);
Steema.TeeChart.Functions.CrossPoints impCrossPointDP = new Steema.TeeChart.Functions.CrossPoints(tChartInterconnector.Chart);

for (int i = 0; i < dpRow.Length; i++)
{
  //code to fill data into flowDPLine, exportLimitDPLine and importLimitDPLine
}

exportPointDP.DataSource = new object[] { exportLimitDPLine, flowDPLine };
exportPointDP.Function = expCrossPointDP;
exportPointDP.CheckDataSource();
importPointDP.DataSource = new object[] { importLimitDPLine, flowDPLine };
importPointDP.Function = impCrossPointDP;
importPointDP.CheckDataSource();
Thanks.

Pep
Site Admin
Site Admin
Posts: 3272
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Aug 18, 2008 8:43 am

Hello,

it cannot be applied directly to this part of code, in case you're a source code customer you can edit the Crosspoints.cs unit and update the code of the DoCalculation method for the one Chris attached on his post (it includes the fix). Another way would be to wait for next maintenance release which will be out in a month, or as he said, manually create a CrossPoints funcion which derive of the existing one and override the DoCalculation method.

Lothar Leischnig
Newbie
Newbie
Posts: 12
Joined: Mon Jan 07, 2008 12:00 am

Re: Exception: Index was outside the bounds of the array

Post by Lothar Leischnig » Mon Jul 20, 2009 1:10 pm

Hello,

i have a similar problem. I'm using a wpf teechart control inside a usercontrol in an application with live data. The chart is placed in a WPF host inside a windows form application. An IndexOutOfRangeException occurs sporadically only when i'm using the markstip tool (MouseAction = Click). Many zooms and clicks where done correctly but in any cases the application crashes when i'm change the window.

I have already implemented the beforedraw event like in a post above, but it has no effect.

The full exception stacktrace is:

Code: Select all

Exception:System.IndexOutOfRangeException
TargetSite:
Double CalcXPos(Int32)
StackTrace(from Exception):
   bei Steema.TeeChart.WPF.Styles.Series.CalcXPos(Int32 index)
   bei Steema.TeeChart.WPF.Styles.CustomPoint.CalcXPos(Int32 valueIndex)
   bei Steema.TeeChart.WPF.Styles.CustomPoint.Clicked(Double x, Double y)
   bei Steema.TeeChart.WPF.Styles.Custom.Clicked(Double x, Double y)
   bei Steema.TeeChart.WPF.Tools.MarksTip.MouseEvent(MouseEventKinds kind, MouseEventArgs e, Cursor& c)
   bei Steema.TeeChart.WPF.Chart.BroadcastMouseEvent(MouseEventKinds kind, MouseEventArgs e, Cursor& c)
   bei Steema.TeeChart.WPF.Chart.BroadcastMouseEvent(MouseEventKinds kind, MouseEventArgs e, ModifierKeys modKeys, Cursor& c)
   bei Steema.TeeChart.WPF.Chart.DoMouseDown(Boolean IsDoubleClick, MouseEventArgs e, ModifierKeys Shift)
   bei Steema.TeeChart.WPF.TChart.OnMouseDown(MouseButtonEventArgs e)
   bei System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
   bei System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   bei System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   bei System.Windows.Input.InputManager.ProcessStagingArea()
   bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   bei System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   bei System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   bei System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   bei MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   bei MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
   bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   bei System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
   bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
   bei System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   bei MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   bei System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   bei System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   bei System.Windows.Forms.Application.Run(Form mainForm)
   bei HtMainApp.Program.Main()
Have you any idea ?

Thanks in advance

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

Re: Exception: Index was outside the bounds of the array

Post by Narcís » Mon Jul 20, 2009 3:13 pm

Hi Lothar,

Can you attach a simple example project we can run "as-is" to reproduce the problem here and let us know the exact steps we should follow to reproduce it and the exact TeeChart version you are using?

Thanks in advance.
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

Lothar Leischnig
Newbie
Newbie
Posts: 12
Joined: Mon Jan 07, 2008 12:00 am

Re: Exception: Index was outside the bounds of the array

Post by Lothar Leischnig » Tue Jul 21, 2009 5:50 am

I'm sorry the wpf control is inside a complex project. There is no way at the moment to exclude all of the functionality for the chart...the library with my own wrapper control for the chart is attached with this post. The chart usercontrol is called Chart.xaml. The version of teechart wpf control is 3.5.3470.15475.

Thanks
Attachments
XamlControls.zip
(8.68 KiB) Downloaded 580 times

Post Reply