Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #747 - crash shoebox #748

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/openstudio_app/OpenStudioApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,14 +1553,16 @@ void OpenStudioApp::loadShoeboxModel() {
versionTranslator.setAllowNewerVersions(false);

auto filePath = resourcesPath() / toPath("ShoeboxModel/ShoeboxExample.osm");
boost::optional<openstudio::model::Model> model = versionTranslator.loadModel(filePath);
if (!model && isOpenStudioApplicationRunningFromBuildDirectory()) {
boost::optional<openstudio::model::Model> model_;
if (openstudio::filesystem::is_regular_file(filePath)) {
Copy link
Collaborator

@macumber macumber Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this the line that prevents the crash? Or one of the lines below checking that currentDocument is not null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentDocument not null.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific change is mostly because I found it annoying and counterproductive to try to load a model and get a warning/error on the console like "Cannot resolve path 'xxxx', model can't be loaded".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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<OSDocument>(componentLibrary(), resourcesPath(), model, toQString(filePath), false, startTabIndex());
if (model_) {
m_osDocument = std::make_shared<OSDocument>(componentLibrary(), resourcesPath(), model_, toQString(filePath), false, startTabIndex());
m_osDocument->setSavePath("");
connectOSDocumentSignals();

Expand Down
3 changes: 2 additions & 1 deletion src/shared_gui_components/LocalLibraryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ QWidget* LibraryItemDelegate::view(QSharedPointer<OSListItem> 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);
Expand Down
3 changes: 2 additions & 1 deletion src/shared_gui_components/WorkflowController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ QWidget* MeasureStepItemDelegate::view(QSharedPointer<OSListItem> 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'.");
Expand Down
Loading