BoltBait/CodeLab

Setting DoubleValueSlider range to [-16777216,16777216] before previewing causes PDN to crash with System.OverflowException

Opened this issue · 3 comments

Steps to reproduce:

  1. Change the range of a double UI variable to [-16777216,16777216].
  2. Click the icon to preview the effect.
  3. Observe Paint.Net to crash with System.OverflowException: Overflow error.

Stack-trace:

System.OverflowException: Overflow error.
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at PaintDotNet.Controls.PdnTrackBar.PaintTicks(Graphics g) in D:\src\pdn\src_5_0_x\Framework\Controls\PdnTrackBar.cs:line 792
   at PaintDotNet.Controls.PdnTrackBar.PaintThemed(Graphics g, Rectangle clipRectangle, Rectangle trackRect, Rectangle thumbRect) in D:\src\pdn\src_5_0_x\Framework\Controls\PdnTrackBar.cs:line 775
   at PaintDotNet.Controls.PdnTrackBar.OnPaint(PaintEventArgs e) in D:\src\pdn\src_5_0_x\Framework\Controls\PdnTrackBar.cs:line 730
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

The crash log:
pdncrash.2.log

This isn't a CodeLab bug, it's due to how Paint.NET is internally implemented. Unfortunately the tl;dr is that you'll just need to use a different range for the property.

The sliders are internally using ints for the range, and in order to accommodate doubles they use an integer range that is based on the double range with a scale factor based on the number of decimal places. In this case it's unable to use the range [-16777216000, +167777216000] because that's beyond the range of an int.

You might also try setting the DecimalPlaces control property to 0 or 1. But, ultimately, this is just not the intended range for a DoubleProperty.

Hmm, fair enough. But I think there's still an issue with CodeLab in that it should sanity-check the range values that are given in the user's source code, perhaps apply a safe upper limit before proceeding or show an error message, in order to avoid a Paint.NET crash that comes out of the blue with no prior warning.

The range limits are up to PDN, not CodeLab. There's no way for CodeLab to really know what the limits are. There's always the possibility that PDN could improve on the limits.