From b4abca85c130d4b995ea9e92bb15cb9c5d2a665c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Sat, 9 Jul 2022 16:32:29 +0200 Subject: [PATCH] Prevent crash on setup parsing file error + activate first mode if none specified --- Software/PC_Application/appwindow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Software/PC_Application/appwindow.cpp b/Software/PC_Application/appwindow.cpp index ef25f9e..dc92e3e 100644 --- a/Software/PC_Application/appwindow.cpp +++ b/Software/PC_Application/appwindow.cpp @@ -1117,6 +1117,8 @@ void AppWindow::LoadSetup(QString filename) } catch (exception &e) { InformationBox::ShowError("Error", "Failed to parse the setup file (" + QString(e.what()) + ")"); qWarning() << "Parsing of setup file failed: " << e.what(); + file.close(); + return; } file.close(); LoadSetup(j); @@ -1170,6 +1172,10 @@ void AppWindow::LoadSetup(nlohmann::json j) break; } } + // if no mode is activated, there might have been a problem with the setup file. Activate the first mode anyway, to prevent invalid GUI state + if(!Mode::getActiveMode() && Mode::getModes().size() > 0) { + Mode::getModes()[0]->activate(); + } } Device *&AppWindow::getDevice()