-
Notifications
You must be signed in to change notification settings - Fork 25
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 the crash in schedules view #614
Conversation
src/openstudio_lib/SchedulesView.cpp
Outdated
@@ -453,27 +453,29 @@ void SchedulesView::showDefaultScheduleDay(const model::ScheduleRuleset& schedul | |||
void SchedulesView::showSummerScheduleDay(const model::ScheduleRuleset& schedule) { | |||
setUpdatesEnabled(false); | |||
|
|||
model::ScheduleRuleset scheduleRuleset = schedule; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't doubt that this works. But this looks fishy, taking something by const ref then making a copy.
Worst case we should take by value.
In any case we need a comment explaining why we do this.
More interestingly, why is that happening? Did you track it down?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested that the fix works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is fishy, you're right a comment will help. Here is what was happening:
- NewProfileView is created storing m_scheduleRuleset
- NewProfileView::onAddClicked emits a signal (e.g. addSummerProfileClicked) with a reference to m_scheduleRuleset
- SchedulesTabController slot (e.g. addSummerProfile) receives the m_scheduleRuleset reference and makes the new scheduleDay object
- SchedulesTabController slot tells the current SchedulesView to draw the new scheduleDay (e.g. showSummerScheduleDay)
- The SchedulesView deletes all the current widgets including NewProfileView which deletes its m_scheduleRuleset object, this invalidates the schedule reference passed to the function (e.g. showSummerScheduleDay)
The fix just creates a shallow copy of the schedule reference before deleting widgets. I updated it to make a const copy just to be a bit more correct. Another solution would be to call deleteLater
on the widgets instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @macumber
Fixes #613 and addresses part of #617