0
Under review
Null ref after clearing series points
I am working on Xamarin iOS (MonoTouch).
I am trying to clear all of the points from a series and add a fresh collection. If I clear the current list of points, I get a null ref afterwards when I click on the plot (at Oxyplot's LineSeries 'GetNearestPoint' method).
If I don't clear the list and just append the points, the crash is avoided but strangely they show up on a separate line, almost like a new series.
I even tried clearing the PlotModel's list of series and adding a fresh one with the new points, but find the same null ref crash.
It seems that the PlotView is trying to find the 'nearest point' from the old points which no longer exist, and my new points are acting like a separate collection. I can't see why this would be happening.
I am trying to clear all of the points from a series and add a fresh collection. If I clear the current list of points, I get a null ref afterwards when I click on the plot (at Oxyplot's LineSeries 'GetNearestPoint' method).
If I don't clear the list and just append the points, the crash is avoided but strangely they show up on a separate line, almost like a new series.
I even tried clearing the PlotModel's list of series and adding a fresh one with the new points, but find the same null ref crash.
It seems that the PlotView is trying to find the 'nearest point' from the old points which no longer exist, and my new points are acting like a separate collection. I can't see why this would be happening.
Customer support service by UserEcho
System.NullReferenceException: Object reference not set to an instance of an object
at OxyPlot.Series.LineSeries.GetNearestPoint (ScreenPoint point, Boolean interpolate) [0x00000] in <filename unknown>:0
at OxyPlot.Series.Series.HitTestOverride (OxyPlot.HitTestArguments args) [0x00000] in <filename unknown>:0
at OxyPlot.UIElement.HitTest (OxyPlot.HitTestArguments args) [0x00000] in <filename unknown>:0
at OxyPlot.Model+<HitTest>d__0.MoveNext () [0x00000] in <filename unknown>:0
at OxyPlot.Model.HandleTouchStarted (System.Object sender, OxyPlot.OxyTouchEventArgs e) [0x00000] in <filename unknown>:0
at OxyPlot.ControllerBase.HandleTouchStarted (IView view, OxyPlot.OxyTouchEventArgs args) [0x00000] in <filename unknown>:0
at OxyPlot.Xamarin.iOS.PlotView.TouchesBegan (Foundation.NSSet touches, UIKit.UIEvent evt) [0x00000] in <filename unknown>:0
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
at Verto.iOS.Application.Main (System.String[] args) [0x00008] in /Users/ryanpalmer/Documents/Clients/Git_Repos/V/Verto/verto iOS/Verto.iOS/Main.cs:17
if (interpolate && this.Smooth && this.SmoothedPoints != null)
{
var result = this.GetNearestInterpolatedPointInternal(this.SmoothedPoints, point);
result.Text = this.Format( this.TrackerFormatString,
result.Item, // Crashes here!!
this.Title,
this.XAxis.Title ?? XYAxisSeries.DefaultXAxisTitle,
this.XAxis.GetValue(result.DataPoint.X),
this.YAxis.Title ?? XYAxisSeries.DefaultYAxisTitle
this.YAxis.GetValue(result.DataPoint.Y));
}
At a guess, when the 'normal' point collection is modified, the smoothed points aren't updated?? I am using the Xamarin component so I had to just make my 'own' class which is a duplicate of LineSeries and step through it, but that means I cant dive any deeper very easily and I don't have time right now.
Cheers,
Ryan
Could it be a race condition issue? Or can it be reproduced in a simple example?
I will try to do that when I get time. I have my boss breathing down my neck for a slipping deadline but I will do my best! :) Thanks for all your hard work, cheers dude.
Ryan
<oxy:PlotView x:Name="plotView"">
<oxy:PlotView.Axes>
<oxy:LinearAxis Title="[°C]" Position="Left" Key="Left" TickStyle="Inside" IsZoomEnabled="False" IsPanEnabled="False" MajorGridlineThickness="1" MajorGridlineStyle="Solid" MaximumPadding="0.05" MinimumPadding="0.05"/>
<oxy:DateTimeAxis Position="Bottom" StringFormat="dd/MM/yy HH:mm" AxisTitleDistance="22" AxisTickToLabelDistance="20" IntervalLength="75" MajorGridlineThickness="1" MajorGridlineStyle="Solid"/>
<oxy:LinearAxis Title="[%]" Position="Right" Key="Right" IsZoomEnabled="False" IsPanEnabled="False" MaximumPadding="0.05" MinimumPadding="0.05"/>
</oxy:PlotView.Axes>
<oxy:PlotView.Series>
<oxy:LineSeries x:Name="TIn" Title="T In" ItemsSource="{Binding t_in_series}" Color="{DynamicResource t_in_color}"/>
<oxy:LineSeries Title="T In0" ItemsSource="{Binding t_in0_series}" Color="{DynamicResource t_in0_color}"/>
<oxy:LineSeries Title="T Out" ItemsSource="{Binding t_out_series}" Color="{DynamicResource t_out_color}"/>
</oxy:PlotView.Series> </oxy:PlotView>
In constructor I'm dynamically creating custom legend using checkbox IsCheckedProperty two way binding with series VisibilityProperty. This allows to hide/unhide series of a plot.
to replicate a problem one needs to do a trick
in constructor of a control I'm setting all series Visibility to Hidden.
when control is render at starts all series are hidden and all checkboxes are "unchecked"
"checking" checkbox causes exception described by RyanBuzzInteractive
I have discovered that calling series visibility using a button click function is not causing an exception after "checking" checkbox. It seems that plot has to rendered before setting series visibility.
By now I do not know how to call rendering manually.
Regards,
Rafal
plotView.InvalidatePlot(true);
it was possible to create a two way binding between checkbox and series visibility but I had to add Click callback just to call InvalidatePlot(true)
duration 7h :D