Skip to content

Commit

Permalink
Fix crash on exit due to bad parenting/shutdown sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Apr 4, 2017
1 parent 4928ccc commit ab25a46
Show file tree
Hide file tree
Showing 40 changed files with 92 additions and 109 deletions.
6 changes: 6 additions & 0 deletions src/FactSystem/Fact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "QGCMAVLink.h"

#include <QtQml>
#include <QQmlEngine>

Fact::Fact(QObject* parent)
: QObject(parent)
Expand All @@ -27,6 +28,9 @@ Fact::Fact(QObject* parent)
{
FactMetaData* metaData = new FactMetaData(_type, this);
setMetaData(metaData);

// Better sage than sorry on object ownership
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
}

Fact::Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObject* parent)
Expand All @@ -41,12 +45,14 @@ Fact::Fact(int componentId, QString name, FactMetaData::ValueType_t type, QObjec
{
FactMetaData* metaData = new FactMetaData(_type, this);
setMetaData(metaData);
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
}

Fact::Fact(const Fact& other, QObject* parent)
: QObject(parent)
{
*this = other;
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
}

const Fact& Fact::operator=(const Fact& other)
Expand Down
4 changes: 2 additions & 2 deletions src/FactSystem/FactSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

const char* FactSystem::_factSystemQmlUri = "QGroundControl.FactSystem";

FactSystem::FactSystem(QGCApplication* app)
: QGCTool(app)
FactSystem::FactSystem(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/FactSystem/FactSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FactSystem : public QGCTool

public:
/// All access to FactSystem is through FactSystem::instance, so constructor is private
FactSystem(QGCApplication* app);
FactSystem(QGCApplication* app, QGCToolbox* toolbox);

// Override from QGCTool
virtual void setToolbox(QGCToolbox *toolbox);
Expand Down
4 changes: 2 additions & 2 deletions src/FirmwarePlugin/FirmwarePluginManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "FirmwarePluginManager.h"
#include "FirmwarePlugin.h"

FirmwarePluginManager::FirmwarePluginManager(QGCApplication* app)
: QGCTool(app)
FirmwarePluginManager::FirmwarePluginManager(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
, _genericFirmwarePlugin(NULL)
{

Expand Down
2 changes: 1 addition & 1 deletion src/FirmwarePlugin/FirmwarePluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FirmwarePluginManager : public QGCTool
Q_OBJECT

public:
FirmwarePluginManager(QGCApplication* app);
FirmwarePluginManager(QGCApplication* app, QGCToolbox* toolbox);
~FirmwarePluginManager();

/// Returns list of firmwares which are supported by the system
Expand Down
4 changes: 2 additions & 2 deletions src/FlightDisplay/VideoManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
QGC_LOGGING_CATEGORY(VideoManagerLog, "VideoManagerLog")

//-----------------------------------------------------------------------------
VideoManager::VideoManager(QGCApplication* app)
: QGCTool(app)
VideoManager::VideoManager(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
, _videoSurface(NULL)
, _videoReceiver(NULL)
, _videoRunning(false)
Expand Down
2 changes: 1 addition & 1 deletion src/FlightDisplay/VideoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class VideoManager : public QGCTool
Q_OBJECT

public:
VideoManager (QGCApplication* app);
VideoManager (QGCApplication* app, QGCToolbox* toolbox);
~VideoManager ();

Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
Expand Down
9 changes: 2 additions & 7 deletions src/FollowMe/FollowMe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "Vehicle.h"
#include "PositionManager.h"

FollowMe::FollowMe(QGCApplication* app)
: QGCTool(app), estimatation_capabilities(0)
FollowMe::FollowMe(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox), estimatation_capabilities(0)
{
memset(&_motionReport, 0, sizeof(motionReport_s));
runTime.start();
Expand All @@ -27,11 +27,6 @@ FollowMe::FollowMe(QGCApplication* app)
connect(&_gcsMotionReportTimer, &QTimer::timeout, this, &FollowMe::_sendGCSMotionReport);
}

FollowMe::~FollowMe()
{
_disable();
}

void FollowMe::followMeHandleManager(const QString&)
{
QmlObjectListModel & vehicles = *_toolbox->multiVehicleManager()->vehicles();
Expand Down
3 changes: 1 addition & 2 deletions src/FollowMe/FollowMe.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class FollowMe : public QGCTool
Q_OBJECT

public:
FollowMe(QGCApplication* app);
~FollowMe();
FollowMe(QGCApplication* app, QGCToolbox* toolbox);

public slots:
void followMeHandleManager(const QString&);
Expand Down
4 changes: 2 additions & 2 deletions src/GAudioOutput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include <QtAndroidExtras/QAndroidJniObject>
#endif

GAudioOutput::GAudioOutput(QGCApplication* app)
: QGCTool(app)
GAudioOutput::GAudioOutput(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
#ifndef __android__
, thread(new QThread())
, worker(new QGCAudioWorker())
Expand Down
2 changes: 1 addition & 1 deletion src/GAudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GAudioOutput : public QGCTool
Q_OBJECT

public:
GAudioOutput(QGCApplication* app);
GAudioOutput(QGCApplication* app, QGCToolbox* toolbox);
~GAudioOutput();

/** @brief List available voices */
Expand Down
4 changes: 2 additions & 2 deletions src/Joystick/JoystickManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ QGC_LOGGING_CATEGORY(JoystickManagerLog, "JoystickManagerLog")
const char * JoystickManager::_settingsGroup = "JoystickManager";
const char * JoystickManager::_settingsKeyActiveJoystick = "ActiveJoystick";

JoystickManager::JoystickManager(QGCApplication* app)
: QGCTool(app)
JoystickManager::JoystickManager(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
, _activeJoystick(NULL)
, _multiVehicleManager(NULL)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Joystick/JoystickManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class JoystickManager : public QGCTool
Q_OBJECT

public:
JoystickManager(QGCApplication* app);
JoystickManager(QGCApplication* app, QGCToolbox* toolbox);
~JoystickManager();

/// List of available joysticks
Expand Down
4 changes: 2 additions & 2 deletions src/MissionManager/MissionCommandTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#include <QQmlEngine>

MissionCommandTree::MissionCommandTree(QGCApplication* app, bool unitTest)
: QGCTool(app)
MissionCommandTree::MissionCommandTree(QGCApplication* app, QGCToolbox* toolbox, bool unitTest)
: QGCTool(app, toolbox)
, _allCommandsCategory(tr("All commands"))
, _settingsManager(NULL)
, _unitTest(unitTest)
Expand Down
2 changes: 1 addition & 1 deletion src/MissionManager/MissionCommandTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MissionCommandTree : public QGCTool
Q_OBJECT

public:
MissionCommandTree(QGCApplication* app, bool unitTest = false);
MissionCommandTree(QGCApplication* app, QGCToolbox* toolbox, bool unitTest = false);

/// Returns the friendly name for the specified command
QString friendlyName(MAV_CMD command);
Expand Down
8 changes: 4 additions & 4 deletions src/PositionManager/PositionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include "QGCApplication.h"
#include "QGCCorePlugin.h"

QGCPositionManager::QGCPositionManager(QGCApplication* app) :
QGCTool(app),
_updateInterval(0),
_currentSource(nullptr)
QGCPositionManager::QGCPositionManager(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
, _updateInterval(0)
, _currentSource(nullptr)
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/PositionManager/PositionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class QGCPositionManager : public QGCTool {

public:

QGCPositionManager(QGCApplication* app);
QGCPositionManager(QGCApplication* app, QGCToolbox* toolbox);
~QGCPositionManager();

enum QGCPositionSource {
Expand Down
2 changes: 1 addition & 1 deletion src/QGCApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static QObject* mavlinkQmlSingletonFactory(QQmlEngine*, QJSEngine*)
static QObject* qgroundcontrolQmlGlobalSingletonFactory(QQmlEngine*, QJSEngine*)
{
// We create this object as a QGCTool even though it isn't in the toolbox
QGroundControlQmlGlobal* qmlGlobal = new QGroundControlQmlGlobal(qgcApp());
QGroundControlQmlGlobal* qmlGlobal = new QGroundControlQmlGlobal(qgcApp(), qgcApp()->toolbox());
qmlGlobal->setToolbox(qgcApp()->toolbox());

return qmlGlobal;
Expand Down
62 changes: 22 additions & 40 deletions src/QGCToolbox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "QGCCorePlugin.h"
#include "QGCOptions.h"
#include "SettingsManager.h"
#include "QGCApplication.h"

#if defined(QGC_CUSTOM_BUILD)
#include CUSTOMHEADER
Expand Down Expand Up @@ -57,28 +58,28 @@ QGCToolbox::QGCToolbox(QGCApplication* app)
, _settingsManager(NULL)
{
// SettingsManager must be first so settings are available to any subsequent tools
_settingsManager = new SettingsManager(app);
_settingsManager = new SettingsManager(app, this);

//-- Scan and load plugins
_scanAndLoadPlugins(app);
_audioOutput = new GAudioOutput(app);
_factSystem = new FactSystem(app);
_firmwarePluginManager = new FirmwarePluginManager(app);
_audioOutput = new GAudioOutput (app, this);
_factSystem = new FactSystem (app, this);
_firmwarePluginManager = new FirmwarePluginManager (app, this);
#ifndef __mobile__
_gpsManager = new GPSManager(app);
_gpsManager = new GPSManager (app, this);
#endif
_imageProvider = new QGCImageProvider(app);
_joystickManager = new JoystickManager(app);
_linkManager = new LinkManager(app);
_mavlinkProtocol = new MAVLinkProtocol(app);
_missionCommandTree = new MissionCommandTree(app);
_multiVehicleManager = new MultiVehicleManager(app);
_mapEngineManager = new QGCMapEngineManager(app);
_uasMessageHandler = new UASMessageHandler(app);
_qgcPositionManager = new QGCPositionManager(app);
_followMe = new FollowMe(app);
_videoManager = new VideoManager(app);
_mavlinkLogManager = new MAVLinkLogManager(app);
_imageProvider = new QGCImageProvider (app, this);
_joystickManager = new JoystickManager (app, this);
_linkManager = new LinkManager (app, this);
_mavlinkProtocol = new MAVLinkProtocol (app, this);
_missionCommandTree = new MissionCommandTree (app, this);
_multiVehicleManager = new MultiVehicleManager (app, this);
_mapEngineManager = new QGCMapEngineManager (app, this);
_uasMessageHandler = new UASMessageHandler (app, this);
_qgcPositionManager = new QGCPositionManager (app, this);
_followMe = new FollowMe (app, this);
_videoManager = new VideoManager (app, this);
_mavlinkLogManager = new MAVLinkLogManager (app, this);
}

void QGCToolbox::setChildToolboxes(void)
Expand Down Expand Up @@ -107,40 +108,21 @@ void QGCToolbox::setChildToolboxes(void)
_mavlinkLogManager->setToolbox(this);
}

QGCToolbox::~QGCToolbox()
{
delete _videoManager;
delete _mavlinkLogManager;
delete _audioOutput;
delete _factSystem;
delete _firmwarePluginManager;
delete _joystickManager;
delete _linkManager;
delete _mavlinkProtocol;
delete _missionCommandTree;
delete _mapEngineManager;
delete _multiVehicleManager;
delete _uasMessageHandler;
delete _followMe;
delete _qgcPositionManager;
delete _corePlugin;
}

void QGCToolbox::_scanAndLoadPlugins(QGCApplication* app)
{
#if defined (QGC_CUSTOM_BUILD)
//-- Create custom plugin (Static)
_corePlugin = (QGCCorePlugin*) new CUSTOMCLASS(app);
_corePlugin = (QGCCorePlugin*) new CUSTOMCLASS(app, app->toolbox());
if(_corePlugin) {
return;
}
#endif
//-- No plugins found, use default instance
_corePlugin = new QGCCorePlugin(app);
_corePlugin = new QGCCorePlugin(app, app->toolbox());
}

QGCTool::QGCTool(QGCApplication* app)
: QObject((QObject*)app)
QGCTool::QGCTool(QGCApplication* app, QGCToolbox* toolbox)
: QObject(toolbox)
, _app(app)
, _toolbox(NULL)
{
Expand Down
13 changes: 7 additions & 6 deletions src/QGCToolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class QGCCorePlugin;
class SettingsManager;

/// This is used to manage all of our top level services/tools
class QGCToolbox {
class QGCToolbox : public QObject {
Q_OBJECT

public:
QGCToolbox(QGCApplication* app);
~QGCToolbox();

FirmwarePluginManager* firmwarePluginManager(void) { return _firmwarePluginManager; }
GAudioOutput* audioOutput(void) { return _audioOutput; }
Expand Down Expand Up @@ -95,11 +95,12 @@ class QGCTool : public QObject {
Q_OBJECT

public:
// All tools are parented to QGCAppliation and go through a two phase creation. First all tools are newed,
// and then setToolbox is called on all tools. The prevents creating an circular dependencies at constructor
// time.
QGCTool(QGCApplication* app);
// All tools must be parented to the QGCToolbox and go through a two phase creation. In the constructor the toolbox
// should only be passed to QGCTool constructor for correct parenting. It should not be referenced or set in the
// protected member. Then in the second phase of setToolbox calls is where you can reference the toolbox.
QGCTool(QGCApplication* app, QGCToolbox* toolbox);

// If you override this method, you must call the base class.
virtual void setToolbox(QGCToolbox* toolbox);

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/QmlControls/QGCImageProvider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <QPainter>
#include <QFont>

QGCImageProvider::QGCImageProvider(QGCApplication *app)
: QGCTool(app)
QGCImageProvider::QGCImageProvider(QGCApplication *app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
, QQuickImageProvider(QQmlImageProviderBase::Image)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/QmlControls/QGCImageProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class QGCImageProvider : public QGCTool, public QQuickImageProvider
{
public:
QGCImageProvider (QGCApplication* app);
QGCImageProvider (QGCApplication* app, QGCToolbox* toolbox);
~QGCImageProvider ();
QImage requestImage (const QString & id, QSize * size, const QSize & requestedSize);
void setImage (QImage* pImage, int id = 0);
Expand Down
4 changes: 2 additions & 2 deletions src/QmlControls/QGroundControlQmlGlobal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const char* QGroundControlQmlGlobal::_flightMapPositionLatitudeSettingsKey =
const char* QGroundControlQmlGlobal::_flightMapPositionLongitudeSettingsKey = "Longitude";
const char* QGroundControlQmlGlobal::_flightMapZoomSettingsKey = "FlightMapZoom";

QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app)
: QGCTool(app)
QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
, _flightMapInitialZoom(14.7) // About 500 meter scale
, _linkManager(NULL)
, _multiVehicleManager(NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/QmlControls/QGroundControlQmlGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class QGroundControlQmlGlobal : public QGCTool
Q_OBJECT

public:
QGroundControlQmlGlobal(QGCApplication* app);
QGroundControlQmlGlobal(QGCApplication* app, QGCToolbox* toolbox);
~QGroundControlQmlGlobal();

Q_PROPERTY(QString appName READ appName CONSTANT)
Expand Down
4 changes: 2 additions & 2 deletions src/QtLocationPlugin/QMLControl/QGCMapEngineManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ QGC_LOGGING_CATEGORY(QGCMapEngineManagerLog, "QGCMapEngineManagerLog")
static const char* kQmlOfflineMapKeyName = "QGCOfflineMap";

//-----------------------------------------------------------------------------
QGCMapEngineManager::QGCMapEngineManager(QGCApplication* app)
: QGCTool(app)
QGCMapEngineManager::QGCMapEngineManager(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox)
, _topleftLat(0.0)
, _topleftLon(0.0)
, _bottomRightLat(0.0)
Expand Down
Loading

0 comments on commit ab25a46

Please sign in to comment.