Skip to content

Commit c658cda

Browse files
authored
Merge pull request #748 from openstudiocoalition/747_CrashShoebox
Fix #747 - crash shoebox
2 parents 46ffa59 + 35a87ec commit c658cda

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/openstudio_app/OpenStudioApp.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,14 +1553,16 @@ void OpenStudioApp::loadShoeboxModel() {
15531553
versionTranslator.setAllowNewerVersions(false);
15541554

15551555
auto filePath = resourcesPath() / toPath("ShoeboxModel/ShoeboxExample.osm");
1556-
boost::optional<openstudio::model::Model> model = versionTranslator.loadModel(filePath);
1557-
if (!model && isOpenStudioApplicationRunningFromBuildDirectory()) {
1556+
boost::optional<openstudio::model::Model> model_;
1557+
if (openstudio::filesystem::is_regular_file(filePath)) {
1558+
model_ = versionTranslator.loadModel(filePath);
1559+
} else if (isOpenStudioApplicationRunningFromBuildDirectory()) {
15581560
filePath = getOpenStudioCoalitionMeasuresSourceDirectory() / toPath("models/ShoeboxExample.osm");
1559-
model = versionTranslator.loadModel(filePath);
1561+
model_ = versionTranslator.loadModel(filePath);
15601562
}
15611563

1562-
if (model) {
1563-
m_osDocument = std::make_shared<OSDocument>(componentLibrary(), resourcesPath(), model, toQString(filePath), false, startTabIndex());
1564+
if (model_) {
1565+
m_osDocument = std::make_shared<OSDocument>(componentLibrary(), resourcesPath(), model_, toQString(filePath), false, startTabIndex());
15641566
m_osDocument->setSavePath("");
15651567
connectOSDocumentSignals();
15661568

src/shared_gui_components/LocalLibraryController.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ QWidget* LibraryItemDelegate::view(QSharedPointer<OSListItem> dataSource) {
497497
// Name
498498

499499
widget->label->setText(libraryItem->displayName());
500-
const bool useClassicCLI = OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI();
500+
const bool useClassicCLI =
501+
OSAppBase::instance()->currentDocument() == nullptr ? false : OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI();
501502
if (useClassicCLI && (measureLanguage == MeasureLanguage::Python)) {
502503
widget->setToolTip("Python Measures are not supported in the Classic CLI.\nYou can change CLI version using 'Preferences->Use Classic CLI'.");
503504
widget->errorLabel->setVisible(true);

src/shared_gui_components/WorkflowController.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ QWidget* MeasureStepItemDelegate::view(QSharedPointer<OSListItem> dataSource) {
570570

571571
connect(measureStepItem.data(), &MeasureStepItem::selectedChanged, workflowStepView->workflowStepButton, &WorkflowStepButton::setHasEmphasis);
572572

573-
const bool useClassicCLI = OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI();
573+
const bool useClassicCLI =
574+
OSAppBase::instance()->currentDocument() == nullptr ? false : OSAppBase::instance()->currentDocument()->mainWindow()->useClassicCLI();
574575
if (useClassicCLI && (measureLanguage == MeasureLanguage::Python)) {
575576
workflowStepView->workflowStepButton->errorLabel->setToolTip(
576577
"Python Measures are not supported in the Classic CLI.\nYou can change CLI version using 'Preferences->Use Classic CLI'.");

0 commit comments

Comments
 (0)