From f7bb93689f2e5dd348d446a173f435ada59c56cc Mon Sep 17 00:00:00 2001
From: Johnny Jazeix <jazeix@gmail.com>
Date: Sat, 1 Jul 2023 14:30:19 +0200
Subject: [PATCH] prevent crashes when opening the plugins window and no trace
 is loaded

---
 src/interface/Interface_graphic.cpp  | 10 ++++++++--
 src/plugin/Command_window.cpp        |  1 -
 src/statistics/Statistics_window.cpp |  1 -
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/interface/Interface_graphic.cpp b/src/interface/Interface_graphic.cpp
index 65839472..ebbf73a0 100644
--- a/src/interface/Interface_graphic.cpp
+++ b/src/interface/Interface_graphic.cpp
@@ -807,6 +807,12 @@ void Interface_graphic::on_about_triggered(){
 
 void Interface_graphic::on_show_plugins_triggered()
 {
+    // Don't open the window if no trace is loaded.
+    // This avoids crashes when the plugin does not check if the trace is valid
+    if( _core->get_trace() == nullptr ) {
+        return;
+    }
+
     if(_plugin_window == nullptr) { //Creation of the window
         _plugin_window = new Plugin_window( _core, this );
     }
@@ -814,11 +820,11 @@ void Interface_graphic::on_show_plugins_triggered()
     if( _core->get_trace() != nullptr ) {
         _plugin_window->update_trace();
     }
-    
+
     if( _core->get_render() != nullptr ) {
         _plugin_window->update_render();
     }
-    
+
     _plugin_window->show();
 }
 
diff --git a/src/plugin/Command_window.cpp b/src/plugin/Command_window.cpp
index 0ba8b6ef..f8321598 100644
--- a/src/plugin/Command_window.cpp
+++ b/src/plugin/Command_window.cpp
@@ -50,7 +50,6 @@
 #include <sstream>
 /* -- */
 #include <QTreeWidgetItem>
-#include <QGLWidget>
 #include <QTextEdit>
 #include <QPushButton>
 #include <QRadioButton>
diff --git a/src/statistics/Statistics_window.cpp b/src/statistics/Statistics_window.cpp
index adca8d91..6fd55c6d 100644
--- a/src/statistics/Statistics_window.cpp
+++ b/src/statistics/Statistics_window.cpp
@@ -11,7 +11,6 @@
 /* -- */
 #include <QFileDialog> // To choose the file to save
 #include <QKeyEvent>
-#include <QGLWidget>
 #include <QGraphicsLayout>
 /* -- */
 #include "common/common.hpp"
-- 
GitLab