Skip to content

Commit

Permalink
UI: Add cleanup of stats callback on window close
Browse files Browse the repository at this point in the history
Moving the cleanup to OBS_FRONTEND_EVENT_EXIT in #8735 only handled the
cleanup from the dockable window, as the regular stats window is deleted
on close when the UI is shut down. This caused an event handler leak
each time the window is manually closed, resulting in crashes. This code
looks a bit wrong since we delete the same handler in multiple places,
but this is due to the code being used by both the dock (non-closable)
and the window (closable). The OBS_FRONTEND_EVENT_EXIT handler handles
cleanup from the dockable stats window, and the window close handler now
handles cleanup from the non-dockable stats window.
  • Loading branch information
notr1ch authored and Lain-B committed Sep 11, 2023
1 parent 9f3f07d commit d8bf21d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions UI/window-basic-stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ void OBSBasicStats::OBSFrontendEvent(enum obs_frontend_event event, void *ptr)
stats->ResetRecTimeLeft();
break;
case OBS_FRONTEND_EVENT_EXIT:
// This is only reached when the non-closable (dock) stats
// window is being cleaned up. Thee closable stats window is
// already gone by this point as it's deleted on close.
obs_frontend_remove_event_callback(OBSFrontendEvent, stats);
break;
default:
Expand Down Expand Up @@ -231,6 +234,10 @@ void OBSBasicStats::closeEvent(QCloseEvent *event)
config_save_safe(main->Config(), "tmp", nullptr);
}

// This code is only reached when the non-dockable stats window is
// manually closed or OBS is exiting.
obs_frontend_remove_event_callback(OBSFrontendEvent, this);

QWidget::closeEvent(event);
}

Expand Down

0 comments on commit d8bf21d

Please sign in to comment.