Skip to content

Commit

Permalink
Prevent destructor from starting when fitsview is being updated
Browse files Browse the repository at this point in the history
  • Loading branch information
murveit authored and knro committed Apr 12, 2022
1 parent b028a6e commit 752ed71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
20 changes: 6 additions & 14 deletions kstars/fitsviewer/fitsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <QApplication>
#include <QImageReader>
#include <QGestureEvent>
#include <QMutexLocker>

#ifndef _WIN32
#include <unistd.h>
Expand Down Expand Up @@ -208,20 +209,7 @@ FITSView::FITSView(QWidget * parent, FITSMode fitsMode, FITSScale filterType) :
m_UpdateFrameTimer.setSingleShot(true);
connect(&m_UpdateFrameTimer, &QTimer::timeout, this, [this]()
{
if (m_ImageFrame)
{
if (toggleStretchAction)
toggleStretchAction->setChecked(stretchImage);

// We employ two schemes for managing the image and its overlays, depending on the size of the image
// and whether we need to therefore conserve memory. The small-image strategy explicitly scales up
// the image, and writes overlays on the scaled pixmap. The large-image strategy uses a pixmap that's
// the size of the image itself, never scaling that up.
if (isLargeImage())
updateFrameLargeImage();
else
updateFrameSmallImage();
}
this->updateFrame(true);
});

connect(&fitsWatcher, &QFutureWatcher<bool>::finished, this, &FITSView::loadInFrame);
Expand All @@ -242,7 +230,9 @@ FITSView::FITSView(QWidget * parent, FITSMode fitsMode, FITSScale filterType) :

FITSView::~FITSView()
{
QMutexLocker locker(&updateMutex);
m_UpdateFrameTimer.stop();
m_Suspended = true;
fitsWatcher.waitForFinished();
wcsWatcher.waitForFinished();
}
Expand Down Expand Up @@ -747,6 +737,8 @@ double FITSView::scaleSize(double size)

void FITSView::updateFrame(bool now)
{
QMutexLocker locker(&updateMutex);

// Do not process if suspended.
if (m_Suspended)
return;
Expand Down
6 changes: 4 additions & 2 deletions kstars/fitsviewer/fitsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class FITSData;
class FITSLabel;

class FITSView : public QScrollArea
{
Q_OBJECT
{
Q_OBJECT
Q_PROPERTY(bool suspended MEMBER m_Suspended)

public:
Expand Down Expand Up @@ -429,6 +429,8 @@ class FITSView : public QScrollArea
bool showMagnifyingGlass { false };
bool m_Suspended {false};

QMutex updateMutex;

//Star Profile Viewer
#ifdef HAVE_DATAVISUALIZATION
QPointer<StarProfileViewer> starProfileWidget;
Expand Down

0 comments on commit 752ed71

Please sign in to comment.