Commit f3a2950f authored by Jasem Mutlaq's avatar Jasem Mutlaq

Using QPointer to avoid dangling pointers

parent 4293908f
......@@ -164,7 +164,7 @@ void Guide::checkCCD(int ccdNum)
{
currentCCD = CCDs.at(ccdNum);
connect(currentCCD, SIGNAL(FITSViewerClosed()), this, SLOT(viewerClosed()), Qt::UniqueConnection);
//connect(currentCCD, SIGNAL(FITSViewerClosed()), this, SLOT(viewerClosed()), Qt::UniqueConnection);
connect(currentCCD, SIGNAL(numberUpdated(INumberVectorProperty*)), this, SLOT(processCCDNumber(INumberVectorProperty*)), Qt::UniqueConnection);
connect(currentCCD, SIGNAL(newExposureValue(ISD::CCDChip*,double,IPState)), this, SLOT(checkExposureValue(ISD::CCDChip*,double,IPState)), Qt::UniqueConnection);
......@@ -447,7 +447,7 @@ void Guide::newFITS(IBLOB *bp)
{
INDI_UNUSED(bp);
FITSViewer *fv = currentCCD->getViewer();
//FITSViewer *fv = currentCCD->getViewer();
disconnect(currentCCD, SIGNAL(BLOBUpdated(IBLOB*)), this, SLOT(newFITS(IBLOB*)));
......@@ -471,20 +471,28 @@ void Guide::newFITS(IBLOB *bp)
FITSView *targetImage = targetChip->getImage(FITS_GUIDE);
if (targetImage == NULL)
{
if (Options::guideLogging())
qDebug() << "Guide: guide frame is missing! Capturing again...";
capture();
return;
}
/*if (targetImage == NULL)
{
pmath->set_image(NULL);
guider->setImage(NULL);
calibration->setImage(NULL);
return;
}
}*/
if (Options::guideLogging())
qDebug() << "Guide: recieved guide frame.";
FITSData *image_data = targetImage->getImageData();
if (image_data == NULL)
return;
Q_ASSERT(image_data);
if (darkImage && darkImage->getImageBuffer() != image_data->getDarkFrame())
{
......@@ -497,7 +505,7 @@ void Guide::newFITS(IBLOB *bp)
pmath->set_image(targetImage);
guider->setImage(targetImage);
fv->show();
//fv->show();
// It should be false in case we do not need to process the image for motion
// which happens when we take an image for auto star selection.
......@@ -635,12 +643,12 @@ double Guide::getReticleAngle()
return calibration->getReticleAngle();
}
void Guide::viewerClosed()
/*void Guide::viewerClosed()
{
pmath->set_image(NULL);
guider->setImage(NULL);
calibration->setImage(NULL);
}
}*/
void Guide::processRapidStarData(ISD::CCDChip *targetChip, double dx, double dy, double fit)
{
......
......@@ -252,7 +252,7 @@ public slots:
void startAutoCalibrateGuiding();
void checkAutoCalibrateGuiding(bool successful);
void viewerClosed();
//void viewerClosed();
void dither();
void setSuspended(bool enable);
......
......@@ -61,7 +61,6 @@ cgmath::cgmath() : QObject()
lost_star = false;
useRapidGuide = false;
dec_swap = false;
pimage = NULL;
// square variables
square_idx = DEFAULT_SQR;
......@@ -130,11 +129,11 @@ void cgmath::set_buffer(float *buffer)
void cgmath::set_image(FITSView *image)
{
pimage = image;
guide_frame = image;
if (pimage)
if (guide_frame)
{
FITSData *image_data = pimage->getImageData();
FITSData *image_data = guide_frame->getImageData();
set_buffer(image_data->getImageBuffer());
set_video_params(image_data->getWidth(), image_data->getHeight());
}
......@@ -358,8 +357,8 @@ void cgmath::move_square( double newx, double newy )
square_pos.y = (double)(video_height - square_size);
// FITS Image takes center coords
if (pimage)
pimage->setGuideSquare(square_pos.x+square_size/2, square_pos.y+square_size/2);
if (guide_frame)
guide_frame->setGuideSquare(square_pos.x+square_size/2, square_pos.y+square_size/2);
}
......@@ -373,8 +372,8 @@ void cgmath::resize_square( int size_idx )
square_idx = size_idx;
// check position
if (pimage)
pimage->setGuideBoxSize(square_size);
if (guide_frame)
guide_frame->setGuideBoxSize(square_size);
}
......
......@@ -12,17 +12,19 @@
#ifndef GMATH_H_
#define GMATH_H_
#include <stdint.h>
#include <sys/types.h>
#include <QObject>
#include <QTime>
#include <QPointer>
#include "fitsviewer/fitsview.h"
#include <stdint.h>
#include <sys/types.h>
#include "vect.h"
#include "matr.h"
#include "common.h"
class FITSView;
typedef struct
{
int size;
......@@ -148,7 +150,7 @@ public:
void set_image(FITSView *image);
bool get_dec_swap() { return dec_swap;}
void set_dec_swap(bool enable) { dec_swap = enable;}
FITSView *get_image() { return pimage; }
FITSView *get_image() { return guide_frame; }
void set_preview_mode(bool enable) { preview_mode = enable;}
ovr_params_t *prepare_overlays( void );
......@@ -181,7 +183,7 @@ private:
// sys...
uint32_t ticks; // global channel ticker
float *pdata; // pointer to data buffer
FITSView *pimage; // pointer to image
QPointer<FITSView> guide_frame; // pointer to image
int video_width, video_height; // video frame dimensions
double ccd_pixel_width, ccd_pixel_height, aperture, focal;
Matrix ROT_Z;
......
......@@ -41,7 +41,6 @@ rguider::rguider(cgmath *mathObject, Ekos::Guide *parent)
pmain_wnd = parent;
pimage = NULL;
phd2 = NULL;
targetChip = NULL;
......@@ -386,8 +385,8 @@ bool rguider::start()
Options::setRAMinimumPulse(ui.spinBox_MinPulseRA->value());
Options::setDECMinimumPulse(ui.spinBox_MinPulseDEC->value());
if (pimage)
disconnect(pimage, SIGNAL(guideStarSelected(int,int)), 0, 0);
if (guideFrame)
disconnect(guideFrame, SIGNAL(guideStarSelected(int,int)), 0, 0);
if (phd2)
{
......@@ -452,8 +451,8 @@ bool rguider::stop()
return phd2->stopGuiding();
}
if (pimage)
connect(pimage, SIGNAL(guideStarSelected(int,int)), this, SLOT(guideStarSelected(int,int)));
if (guideFrame)
connect(guideFrame, SIGNAL(guideStarSelected(int,int)), this, SLOT(guideStarSelected(int,int)));
ui.pushButton_StartStop->setText( i18n("Start Autoguide") );
pmain_wnd->appendLogText(i18n("Autoguiding stopped."));
pmath->stop();
......@@ -663,10 +662,10 @@ void rguider::guide( void )
void rguider::setImage(FITSView *image)
{
pimage = image;
guideFrame = image;
if (m_isReady && pimage && m_isStarted == false)
connect(pimage, SIGNAL(guideStarSelected(int,int)), this, SLOT(guideStarSelected(int, int)));
if (m_isReady && guideFrame && m_isStarted == false)
connect(guideFrame, SIGNAL(guideStarSelected(int,int)), this, SLOT(guideStarSelected(int, int)));
}
void rguider::guideStarSelected(int x, int y)
......
......@@ -97,7 +97,7 @@ private:
custom_drawer *pDriftOut;
cscroll_graph *drift_graph;
FITSView *pimage;
QPointer<FITSView> guideFrame;
bool m_isStarted;
bool m_isReady;
bool m_isSubFramed;
......
......@@ -882,8 +882,7 @@ void rcalibration::capture()
bool rcalibration::setImage(FITSView *image)
{
if (image == NULL)
return false;
guideFrame = image;
switch (calibrationStage)
{
......@@ -897,11 +896,11 @@ bool rcalibration::setImage(FITSView *image)
calibrationStage = CAL_SELECT_STAR;
ui.selectStarLED->setColor(busyColor);
FITSData *image_data = image->getImageData();
FITSData *image_data = guideFrame->getImageData();
setVideoParams(image_data->getWidth(), image_data->getHeight());
QPair<double,double> star = selectAutoStar(image);
QPair<double,double> star = selectAutoStar(guideFrame);
if (ui.autoStarCheck->isChecked())
{
......@@ -909,7 +908,7 @@ bool rcalibration::setImage(FITSView *image)
return false;
}
else
connect(image, SIGNAL(guideStarSelected(int,int)), this, SLOT(guideStarSelected(int, int)));
connect(guideFrame, SIGNAL(guideStarSelected(int,int)), this, SLOT(guideStarSelected(int, int)));
}
break;
......@@ -928,6 +927,8 @@ bool brighterThan(Edge *s1, Edge *s2)
QPair<double,double> rcalibration::selectAutoStar(FITSView *image)
{
Q_ASSERT(image);
//int maxVal=-1;
//Edge *guideStar = NULL;
QPair<double,double> star;
......
......@@ -12,6 +12,10 @@
#ifndef RCALIBRATION_H
#define RCALIBRATION_H
#include <QPointer>
#include "fitsviewer/fitsview.h"
#include "gmath.h"
#include "../guide.h"
#include "ui_rcalibration.h"
......@@ -116,6 +120,7 @@ private:
CalibrationStage calibrationStage;
CalibrationType calibrationType;
QPointer<FITSView> guideFrame;
Ui::rcalibrationClass ui;
......
......@@ -251,7 +251,8 @@ FITSView::FITSView(QWidget * parent, FITSMode fitsMode, FITSScale filterType) :
setBackgroundRole(QPalette::Dark);
guide_x = guide_y = guide_box = -1;
guide_x = guide_y = -1;
guide_box = 16;
marker_x = marker_y = -1;
currentZoom = 0.0;
......
......@@ -34,7 +34,6 @@
#include <ekos/ekosmanager.h>
#include "imageviewer.h"
#include "Options.h"
const int MAX_FILENAME_LEN = 1024;
......@@ -419,6 +418,7 @@ void CCDChip::setCanAbort(bool value)
{
CanAbort = value;
}
FITSData *CCDChip::getImageData() const
{
return imageData;
......@@ -1211,13 +1211,11 @@ void CCD::processBLOB(IBLOB* bp)
}
}
QUrl url = QUrl::fromLocalFile(filename);
ImageViewer *iv = new ImageViewer(url.path());
if (iv)
{
iv->show();
QFile::remove(filename);
}
if (imageViewer.isNull())
imageViewer = new ImageViewer(getDeviceName(), KStars::Instance());
imageViewer->loadImage(filename);
QFile::remove(filename);
}
// Unless we have cfitsio, we're done.
#ifdef HAVE_CFITSIO
......@@ -1225,15 +1223,17 @@ void CCD::processBLOB(IBLOB* bp)
{
QUrl fileURL(filename);
if (fv == NULL)
if (fv.isNull())
{
normalTabID = calibrationTabID = focusTabID = guideTabID = -1;
if (Options::singleWindowCapturedFITS())
fv = KStars::Instance()->genericFITSViewer();
else
fv = new FITSViewer(KStars::Instance());
connect(fv, SIGNAL(destroyed()), this, SLOT(FITSViewerDestroyed()));
connect(fv, SIGNAL(destroyed()), this, SIGNAL(FITSViewerClosed()));
//connect(fv, SIGNAL(destroyed()), this, SLOT(FITSViewerDestroyed()));
//connect(fv, SIGNAL(destroyed()), this, SIGNAL(FITSViewerClosed()));
}
FITSScale captureFilter = targetChip->getCaptureFilter();
......
......@@ -14,10 +14,15 @@
#include "indistd.h"
#include <QStringList>
#include <QPointer>
#include <fitsviewer/fitsviewer.h>
#include <fitsviewer/fitsdata.h>
#include <auxiliary/imageviewer.h>
class FITSView;
class FITSViewer;
class FITSData;
class StreamWG;
/**
......@@ -93,7 +98,7 @@ public:
QStringList getISOList() const;
private:
FITSView *normalImage, *focusImage, *guideImage, *calibrationImage;
QPointer<FITSView> normalImage, focusImage, guideImage, calibrationImage;
FITSData *imageData;
FITSMode captureMode;
FITSScale captureFilter;
......@@ -162,7 +167,7 @@ public slots:
void StreamWindowHidden();
signals:
void FITSViewerClosed();
//void FITSViewerClosed();
void newTemperatureValue(double value);
void newExposureValue(ISD::CCDChip *chip, double value, IPState state);
void newGuideStarData(ISD::CCDChip *chip, double dx, double dy, double fit);
......@@ -179,12 +184,16 @@ private:
QString fitsDir;
char BLOBFilename[MAXINDIFILENAME];
int nextSequenceID;
FITSViewer * fv;
StreamWG *streamWindow;
int streamW, streamH;
ISD::ST4 *ST4Driver;
int normalTabID, calibrationTabID, focusTabID, guideTabID;
CCDChip *primaryChip, *guideChip;
CCDChip *primaryChip, *guideChip;
QPointer<FITSViewer> fv;
QPointer<ImageViewer> imageViewer;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment