Skip to content

Commit 40f0940

Browse files
committed
Re-timing DeviceView set up to avoid crash resolving #2564
* Allowing the paintEvent to drive the initial setup of the DeviceView to delay accessing controller features during OpenRGB initialisation.
1 parent 1ff192b commit 40f0940

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

qt/DeviceView.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ DeviceView::DeviceView(QWidget *parent) :
3535
size = width();
3636
}
3737

38+
DeviceView::~DeviceView()
39+
{
40+
delete controller;
41+
}
42+
3843
struct led_label
3944
{
4045
QString label_text;
@@ -201,7 +206,10 @@ void DeviceView::setController(RGBController * controller_ptr)
201206
| Store the controller pointer |
202207
\*-----------------------------------------------------*/
203208
controller = controller_ptr;
209+
}
204210

211+
void DeviceView::InitDeviceView()
212+
{
205213
/*-----------------------------------------------------*\
206214
| Set the size of the selection flags vector |
207215
\*-----------------------------------------------------*/
@@ -364,7 +372,7 @@ void DeviceView::setController(RGBController * controller_ptr)
364372
| Calculate LED box positions for single/linear zones |
365373
\*-----------------------------------------------------*/
366374
unsigned int leds_count = controller->zones[zone_idx].leds_count;
367-
375+
368376
for(unsigned int led_idx = 0; led_idx < leds_count; led_idx++)
369377
{
370378
unsigned int led_pos_idx = controller->zones[zone_idx].start_idx + led_idx;
@@ -587,7 +595,7 @@ void DeviceView::paintEvent(QPaintEvent* /* event */)
587595
\*-----------------------------------------------------*/
588596
if(controller->leds.size() != led_pos.size())
589597
{
590-
setController(controller);
598+
InitDeviceView();
591599
}
592600

593601
/*-----------------------------------------------------*\
@@ -722,7 +730,7 @@ void DeviceView::updateSelection()
722730
selectedLeds.push_back(led_idx);
723731
}
724732
}
725-
733+
726734
update();
727735

728736
/*-----------------------------------------------------*\
@@ -788,7 +796,7 @@ bool DeviceView::selectLeds(QVector<int> target)
788796
}
789797

790798
update();
791-
799+
792800
/*-----------------------------------------------------*\
793801
| Send selection changed signal |
794802
\*-----------------------------------------------------*/
@@ -823,7 +831,7 @@ bool DeviceView::selectZone(int zone, bool add)
823831
}
824832

825833
update();
826-
834+
827835
/*-----------------------------------------------------*\
828836
| Send selection changed signal |
829837
\*-----------------------------------------------------*/

qt/DeviceView.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class DeviceView : public QWidget
1717
Q_OBJECT
1818
public:
1919
explicit DeviceView(QWidget *parent = 0);
20+
~DeviceView();
2021

2122
virtual QSize sizeHint () const;
2223
virtual QSize minimumSizeHint () const;
@@ -54,14 +55,15 @@ class DeviceView : public QWidget
5455
float matrix_h;
5556

5657
bool numerical_labels;
57-
58+
5859
RGBController* controller;
5960

60-
QColor posColor(const QPoint &point);
61-
void updateSelection();
61+
QColor posColor(const QPoint &point);
62+
void InitDeviceView();
63+
void updateSelection();
6264

6365
signals:
64-
void selectionChanged(QVector<int>);
66+
void selectionChanged(QVector<int>);
6567

6668
public slots:
6769
bool selectLed(int);

0 commit comments

Comments
 (0)