Skip to content

NullReferenceException in too small plots #626

@martin-brajer

Description

@martin-brajer

Left-mouse-double-click the plot, than reduce (ScottPlot.FormsPlot) formsPlot1.Height/Width so that actual plot (inner rectangle) has zero (or lower) height/width. This throws NullReferenceException:

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=ScottPlot
StackTrace:
at ScottPlot.Renderable.Benchmark.Render(Settings settings)
at ScottPlot.Plot.RenderBitmap()
at ScottPlot.Plot.GetBitmap(Boolean renderFirst, Boolean lowQuality)
at ScottPlot.FormsPlot.Render(Boolean skipIfCurrentlyRendering, Boolean lowQuality, Boolean recalculateLayout, Boolean processEvents)
at ScottPlot.FormsPlot.PbPlot_SizeChanged(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnSizeChanged(EventArgs e)
at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
at System.Windows.Forms.Control.UpdateBounds()
at System.Windows.Forms.Control.WmWindowPosChanged(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)

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1() => InitializeComponent();
        private void Form1_Load(object sender, EventArgs e) => formsPlot1.Render();
        private void Form1_Click(object sender, EventArgs e) => formsPlot1.Height = 20;
    }
}

Adding data doesn't help. Double-clicking back and then resizing does not throw the exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BUGunexpected behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions