Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Reference Exception in CartesianChart.Measure with an invisible axes. #470

Closed
EricEzaM opened this issue May 13, 2022 · 2 comments
Closed

Comments

@EricEzaM
Copy link

EricEzaM commented May 13, 2022

Describe the bug
When an axis is configured with IsVisible = false a crash occurs due to an unhandled NullReferenceException. This is common if you want to have a "End" axis hidden until a series is added which is configured to display on the right hand side axis.

To Reproduce
View Model

    public class ViewModel
    {
        public Axis[] YAxes { get; set; } = new[]
        {
            new Axis() { },
            new Axis()
            {
                IsVisible = false,
            }
        };

        public ISeries[] Series { get; set; } = new[]
        {
            new LineSeries<double>
            {
                Values = new double[] { 2, 1, 3, 5, 3, 4, 6 },
                Fill = null
            }
        };
    }

Main Window

    <Window.DataContext>
        <local:ViewModel/>
    </Window.DataContext>
    <lvc:CartesianChart
        Series="{Binding Series}"
        YAxes="{Binding YAxes}">

    </lvc:CartesianChart>
  1. Launch the application
  2. Resize the window so the chart redraws.
  3. The application will crash.

Now, comment out IsVisible = false in the Axis constructor in the view model. The application will no longer crash.

Expected behavior
No crash

Desktop (please complete the following information):

  • OS: Windows 10, .NET Framework 4.8

Additional context
The stack trace does not appear to be all that useful:

Expand to see stacktrace
System.NullReferenceException: Object reference not set to an instance of an object.
   at LiveChartsCore.CartesianChart`1.Measure()
   at LiveChartsCore.Chart`1.<UpdateThrottlerUnlocked>b__144_1()
   at System.Windows.Threading.DispatcherOperation.InvokeDelegateCore()
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Windows.Threading.DispatcherOperation.Wait(TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherOperation operation, CancellationToken cancellationToken, TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.Invoke(Action callback, DispatcherPriority priority, CancellationToken cancellationToken, TimeSpan timeout)
   at System.Windows.Threading.Dispatcher.Invoke(Action callback)
   at LiveChartsCore.SkiaSharpView.WPF.Chart.LiveChartsCore.Kernel.Sketches.IChartView.InvokeOnUIThread(Action action)
   at LiveChartsCore.Chart`1.<UpdateThrottlerUnlocked>b__144_0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at LiveChartsCore.Kernel.ActionThrottler.<Call>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
@EricEzaM EricEzaM changed the title Null Reference Exception in CartesianChart.Measure with an invisible axes and no series. Null Reference Exception in CartesianChart.Measure with an invisible axes. May 13, 2022
@NPadrutt
Copy link

I have the same problem with the latest update.

beto-rodriguez added a commit that referenced this issue May 20, 2022
@beto-rodriguez
Copy link
Owner

Fixed with the refenced commit an will be included in the next version of the library, thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants