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 the crash in schedules view #614

Merged
merged 3 commits into from
Aug 21, 2023
Merged

Fix the crash in schedules view #614

merged 3 commits into from
Aug 21, 2023

Conversation

macumber
Copy link
Collaborator

@macumber macumber commented Jul 23, 2023

Fixes #613 and addresses part of #617

@@ -453,27 +453,29 @@ void SchedulesView::showDefaultScheduleDay(const model::ScheduleRuleset& schedul
void SchedulesView::showSummerScheduleDay(const model::ScheduleRuleset& schedule) {
setUpdatesEnabled(false);

model::ScheduleRuleset scheduleRuleset = schedule;
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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:

  1. NewProfileView is created storing m_scheduleRuleset
  2. NewProfileView::onAddClicked emits a signal (e.g. addSummerProfileClicked) with a reference to m_scheduleRuleset
  3. SchedulesTabController slot (e.g. addSummerProfile) receives the m_scheduleRuleset reference and makes the new scheduleDay object
  4. SchedulesTabController slot tells the current SchedulesView to draw the new scheduleDay (e.g. showSummerScheduleDay)
  5. 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.

@jmarrec jmarrec self-requested a review August 21, 2023 09:41
Copy link
Collaborator

@jmarrec jmarrec left a comment

Choose a reason for hiding this comment

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

Thanks @macumber

@jmarrec jmarrec merged commit b732836 into develop Aug 21, 2023
7 of 8 checks passed
@jmarrec jmarrec deleted the fix-schedule-crash-613 branch August 21, 2023 09:42
@jmarrec jmarrec restored the fix-schedule-crash-613 branch August 21, 2023 09:42
@jmarrec jmarrec deleted the fix-schedule-crash-613 branch August 21, 2023 09:42
@jmarrec jmarrec restored the fix-schedule-crash-613 branch August 21, 2023 09:42
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes with assigning Summer/Winter Schedule
2 participants