Skip to content

Commit

Permalink
Fix MacOS crash issue
Browse files Browse the repository at this point in the history
  • Loading branch information
denverbdr committed Dec 9, 2019
1 parent 142f2d4 commit 497db23
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
21 changes: 16 additions & 5 deletions src/controller.cpp
Expand Up @@ -216,13 +216,24 @@ void Controller::refreshRescanStatus() {
}

void Controller::closeRefreshStatusIfAlive() {
if (rescanProgress) {
delete rescanProgress;
rescanProgress = nullptr;
// For some bizare reason, this function is re-entering on MacOS. That is, while
// "delete rescanProgress" is executing, this function gets called again, on the same
// thread. So use a mutex to prevent double deletes
static QMutex progressDeleteLock(QMutex::NonRecursive);

// Update the status bar
ui->statusBar->showMessage(QObject::tr("Rescan finished"));
if (progressDeleteLock.tryLock()) {
if (rescanProgress) {
rescanProgress->closeProgress();
delete rescanProgress;
rescanProgress = nullptr;

// Update the status bar
ui->statusBar->showMessage(QObject::tr("Rescan finished"));
}

progressDeleteLock.unlock();
}

}

/// This will refresh all the balance data from zcashd
Expand Down
9 changes: 6 additions & 3 deletions src/rescanprogress.cpp
Expand Up @@ -14,11 +14,14 @@ RescanProgress::RescanProgress(MainWindow* _main)
}

RescanProgress::~RescanProgress() {
progress->setValue(100);
progress->deleteLater();
delete progress;
}

void RescanProgress::updateProgress(int tick) {
if (tick >= 0 && tick < 100)
progress->setValue(tick);
}
}

void RescanProgress::closeProgress() {
progress->setValue(100);
}
3 changes: 2 additions & 1 deletion src/rescanprogress.h
Expand Up @@ -10,7 +10,8 @@ class RescanProgress {
~RescanProgress();

void updateProgress(int value);

void closeProgress();

private:
MainWindow* main;
QProgressDialog* progress;
Expand Down

0 comments on commit 497db23

Please sign in to comment.