From fb8112eb7e5d34c0b6924bb79033223618bb7d22 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 10 Aug 2021 04:15:15 +0200 Subject: [PATCH] Fix crash when changing UI scale on Windows When the UI scale changes without the Recorder UI being shown at least once, the Widgets have not yet been realized, size-groups not evaluated, and a widget size of 1x1 is assumed. --- gtk2_ardour/input_port_monitor.cc | 19 ++++++++++++++++--- gtk2_ardour/input_port_monitor.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gtk2_ardour/input_port_monitor.cc b/gtk2_ardour/input_port_monitor.cc index fc097ff436..6fa7c1522e 100644 --- a/gtk2_ardour/input_port_monitor.cc +++ b/gtk2_ardour/input_port_monitor.cc @@ -241,6 +241,15 @@ InputPortMonitor::InputScope::InputScope (samplecnt_t rate, int l, int g, Orient parameter_changed ("waveform-clip-level"); parameter_changed ("show-waveform-clipping"); parameter_changed ("waveform-scale"); + UIConfiguration::instance().DPIReset.connect (sigc::mem_fun (*this, &InputPortMonitor::InputScope::dpi_reset)); +} + +void +InputPortMonitor::InputScope::dpi_reset () +{ + if (is_realized ()) { + queue_resize (); + } } void @@ -282,7 +291,7 @@ InputPortMonitor::InputScope::on_size_allocate (Gtk::Allocation& a) } if (a.get_width () != w || a.get_height () != h) { - _surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, a.get_width () - 2, a.get_height () - 2); + _surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, std::max (1, a.get_width () - 2), std::max (1, a.get_height () - 2)); } } @@ -444,7 +453,9 @@ InputPortMonitor::EventMeter::dpi_reset () _layout->get_pixel_size (_length, _extent); _extent += 2; _length += 2; - queue_resize (); + if (is_realized ()) { + queue_resize (); + } } void @@ -551,7 +562,9 @@ InputPortMonitor::EventMonitor::dpi_reset () _layout->get_pixel_size (_width, _height); _width += 2; _height += 2; - queue_resize (); + if (is_realized ()) { + queue_resize (); + } } void diff --git a/gtk2_ardour/input_port_monitor.h b/gtk2_ardour/input_port_monitor.h index 7b436d7746..b1fa0cbab9 100644 --- a/gtk2_ardour/input_port_monitor.h +++ b/gtk2_ardour/input_port_monitor.h @@ -64,6 +64,7 @@ private: void on_size_allocate (Gtk::Allocation&); private: + void dpi_reset (); int _pos; ARDOUR::samplecnt_t _rate;