Tracker: Clean up AddPoses threads properly.

They may still be running at the point we detach from the window, and
as we stop watching everything else at that point (and the threads
themselves depend on the window looper as the global "lock"), we
need to tear them down then.

We especially cannot do this in the destructor, as there are some
virtual methods that the threads need during their teardown which
obviously will not work in ~BPoseView.

Fixes #13371, and potentially other Tracker crashes that occured
as a result of closing the window while the add-poses tasks were
still operational.

Change-Id: Ib7ec0d1d413096be899a05887399f5b087eb8f99
Reviewed-on: https://review.haiku-os.org/574
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Augustin Cavalier 2018-09-16 19:06:02 -04:00 committed by waddlesplash
parent 15cb367a40
commit 497f099f5a

View File

@ -893,6 +893,17 @@ BPoseView::DetachedFromWindow()
tracker->Unlock();
}
std::set<thread_id> addPosesThreads(fAddPosesThreads);
fAddPosesThreads.clear();
// The threads check periodically if they are still valid,
// and clearing the list makes them all "invalid."
std::set<thread_id>::iterator it;
for (it = addPosesThreads.begin(); it != addPosesThreads.end(); it++) {
UnlockLooper();
wait_for_thread(*it, NULL);
LockLooper();
}
StopWatching();
CommitActivePose();
SavePoseLocations();
@ -10168,7 +10179,7 @@ BPoseView::ShowBarberPole()
void
BPoseView::HideBarberPole()
{
if (fCountView) {
if (fCountView != NULL) {
AutoLock<BWindow> lock(Window());
if (!lock)
return;