Exception during resize

Feb 1, 2012 at 10:50 AM

Hello,

thank you for this great tool, suited perfectly.

During testing our WPF application I encountered an exception in OxyPlot.DataPointSeries.AddDataPoints.
It happened once when I was resizing a window with a plot in it, but I was not able to reproduce this situation.
The plot data are updated periodically in my project, so maybe there was a race condition between updating and resizing?

Maybe the stack trace shown below will help to track down a potential problem.
Anyway I was not able to reproduce it.

Kind regards
Peter

 

Collection was modified; enumeration operation may not execute.

   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Collections.Generic.List`1.Enumerator.MoveNext()
   at OxyPlot.DataPointSeries.AddDataPoints(IList`1 dest, IEnumerable itemsSource, String dataFieldX, String dataFieldY) in D:\Codeplex\OBJO\OxyPlot\trunk\Source\OxyPlot\Series\DataPointSeries.cs:line 313
   at OxyPlot.DataPointSeries.AddDataPoints(IList`1 points) in D:\Codeplex\OBJO\OxyPlot\trunk\Source\OxyPlot\Series\DataPointSeries.cs:line 284
   at OxyPlot.DataPointSeries.UpdateData() in D:\Codeplex\OBJO\OxyPlot\trunk\Source\OxyPlot\Series\DataPointSeries.cs:line 223
   at OxyPlot.AreaSeries.UpdateData() in D:\Codeplex\OBJO\OxyPlot\trunk\Source\OxyPlot\Series\AreaSeries.cs:line 289
   at OxyPlot.PlotModel.Update(Boolean updateData) in D:\Codeplex\OBJO\OxyPlot\trunk\Source\OxyPlot\PlotModel\PlotModel.cs:line 1083
   at OxyPlot.Wpf.Plot.UpdateModel(Boolean updateData) in D:\Codeplex\OBJO\OxyPlot\trunk\Source\OxyPlot.Wpf\Plot.cs:line 1265
   at OxyPlot.Wpf.Plot.CompositionTargetRendering(Object sender, EventArgs e) in D:\Codeplex\OBJO\OxyPlot\trunk\Source\OxyPlot.Wpf\Plot.cs:line 1032
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
   at System.Windows.Interop.HwndTarget.OnResize()
   at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at Keba.KSDD.App.App.Main() in C:\work\Keba.KSDD.SDK\Keba.KSDD.App\obj\x86\Debug\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
Coordinator
Feb 1, 2012 at 11:30 AM

thanks for reporting the bug! I'll have a look at the DataPointSeries.

the invalidate/update logic in the wpf Plot control should be thread safe (unless I did something wrong). Are you updating the PlotModel directly from your code? I see the PlotModel should also be made thread safe, will add it as an issue!

Feb 28, 2014 at 9:39 AM
Hi,
I have same problem now. Not able to solve it.
In WPF application with MVVM pattern, I have the following timer method in the model:
public int ctr = 0;
        void RefreshElapsed(object sender, ElapsedEventArgs e)
        {
            if (Simulated)
            {
                var link = ctr % 10;
                var series = GetDummySeries("Left" + ctr);
                AddSeriesLeft(series, ChartTypeEnum.Voltage, link);
                series = GetDummySeries("Right" + ctr);
                AddSeriesRight(series, ChartTypeEnum.Voltage, link);
            }
            RightPlot.FadeSeries(127, OxyColors.Blue);
            LeftPlot.FadeSeries(127, OxyColors.Blue);
            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
            {
                RightPlot.RefreshPlot(true);
                LeftPlot.RefreshPlot(true);
            }));
            ctr++;
        }
I get the following exception:
A first chance exception of type 'System.InvalidOperationException' occurred in OxyPlot.dll

Additional information: XAxis not defined.

Stack:    at OxyPlot.Series.XYAxisSeries.VerifyAxes() in c:\TeamCity\buildAgent\work\3b9fcf1ba397d0ed\Source\OxyPlot\Series\XYAxisSeries.cs:line 417
First I did not have the invoke but I thought it was a race condition so I made it run in the correct thread, but still something is wrong. Also the XAxis is not defines is really strange, since I actually add xaxis like so in the constructor of the view model:
            LeftPlot.Axes.Add(new LinearAxis(AxisPosition.Bottom, "Time [ms]"));
            RightPlot.Axes.Add(new LinearAxis(AxisPosition.Bottom, "Time [ms]"));
I will try and put some Keys for the default x axis.
Coordinator
Feb 28, 2014 at 11:56 AM
This is something we should investigate closer.
I don't want to simply add a null reference test inside XYAxisSeries before we understand what is happening. I think this may be solved on a higher level, maybe with some synchronization code.
Is it possible to make a unit test that reproduces this error? I guess it is a bit challenging to make this, but that should make defining the issue and solving it much easier!
Coordinator
Mar 1, 2014 at 1:16 PM
Could it be a syncrhonization problem? The model should not be updated while the plot is being refreshed.
I have added a note on this in https://oxyplot.codeplex.com/workitem/10144.