From 02903e2628563f8c31ee2d071b77c339f33c425b Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Thu, 5 Sep 2024 10:16:52 +0200 Subject: [PATCH 1/2] #747 - fixup crash when loading ShoeboxModel from the measures/workflow tab --- src/shared_gui_components/LocalLibraryController.cpp | 3 ++- src/shared_gui_components/WorkflowController.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shared_gui_components/LocalLibraryController.cpp b/src/shared_gui_components/LocalLibraryController.cpp index 504cda2b1..0d9c247eb 100644 --- a/src/shared_gui_components/LocalLibraryController.cpp +++ b/src/shared_gui_components/LocalLibraryController.cpp @@ -497,7 +497,8 @@ QWidget* LibraryItemDelegate::view(QSharedPointer dataSource) { // Name widget->label->setText(libraryItem->displayName()); - const bool useClassicCLI = OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI(); + const bool useClassicCLI = + OSAppBase::instance()->currentDocument() == nullptr ? false : OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI(); if (useClassicCLI && (measureLanguage == MeasureLanguage::Python)) { widget->setToolTip("Python Measures are not supported in the Classic CLI.\nYou can change CLI version using 'Preferences->Use Classic CLI'."); widget->errorLabel->setVisible(true); diff --git a/src/shared_gui_components/WorkflowController.cpp b/src/shared_gui_components/WorkflowController.cpp index 432eb78d3..11b56e316 100644 --- a/src/shared_gui_components/WorkflowController.cpp +++ b/src/shared_gui_components/WorkflowController.cpp @@ -570,7 +570,8 @@ QWidget* MeasureStepItemDelegate::view(QSharedPointer dataSource) { connect(measureStepItem.data(), &MeasureStepItem::selectedChanged, workflowStepView->workflowStepButton, &WorkflowStepButton::setHasEmphasis); - const bool useClassicCLI = OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI(); + const bool useClassicCLI = + OSAppBase::instance()->currentDocument() == nullptr ? false : OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI(); if (useClassicCLI && (measureLanguage == MeasureLanguage::Python)) { workflowStepView->workflowStepButton->errorLabel->setToolTip( "Python Measures are not supported in the Classic CLI.\nYou can change CLI version using 'Preferences->Use Classic CLI'."); From 35a87ecc155c7a65ec065a34c74c573e5896e102 Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Thu, 5 Sep 2024 10:23:10 +0200 Subject: [PATCH 2/2] Avoid trying to loadModel when you can check if file exists first --- src/openstudio_app/OpenStudioApp.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/openstudio_app/OpenStudioApp.cpp b/src/openstudio_app/OpenStudioApp.cpp index 4e6dee3e0..ac561f9bf 100644 --- a/src/openstudio_app/OpenStudioApp.cpp +++ b/src/openstudio_app/OpenStudioApp.cpp @@ -1553,14 +1553,16 @@ void OpenStudioApp::loadShoeboxModel() { versionTranslator.setAllowNewerVersions(false); auto filePath = resourcesPath() / toPath("ShoeboxModel/ShoeboxExample.osm"); - boost::optional model = versionTranslator.loadModel(filePath); - if (!model && isOpenStudioApplicationRunningFromBuildDirectory()) { + boost::optional model_; + if (openstudio::filesystem::is_regular_file(filePath)) { + model_ = versionTranslator.loadModel(filePath); + } else if (isOpenStudioApplicationRunningFromBuildDirectory()) { filePath = getOpenStudioCoalitionMeasuresSourceDirectory() / toPath("models/ShoeboxExample.osm"); - model = versionTranslator.loadModel(filePath); + model_ = versionTranslator.loadModel(filePath); } - if (model) { - m_osDocument = std::make_shared(componentLibrary(), resourcesPath(), model, toQString(filePath), false, startTabIndex()); + if (model_) { + m_osDocument = std::make_shared(componentLibrary(), resourcesPath(), model_, toQString(filePath), false, startTabIndex()); m_osDocument->setSavePath(""); connectOSDocumentSignals();