Skip to content

Commit

Permalink
Fixed various reproducible crashes (closes #1630).
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed May 3, 2018
2 parents 657e34f + 5b16f9b commit 2952b2d
Show file tree
Hide file tree
Showing 16 changed files with 534 additions and 551 deletions.
24 changes: 12 additions & 12 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ MainWindow::MainWindow(const QString &pApplicationDate) :
mLoadedGuiPlugins(Plugins()),
mLoadedPreferencesPlugins(Plugins()),
mLoadedWindowPlugins(Plugins()),
mCoreInterface(0),
mRawLocale(QString()),
mMenus(QMap<QString, QMenu *>()),
mFileNewMenu(0),
Expand Down Expand Up @@ -158,6 +159,11 @@ MainWindow::MainWindow(const QString &pApplicationDate) :
mLoadedWindowPlugins << plugin;
}

// Retrieve our Core plugin's interface, should the Core plugin be loaded

if (mPluginManager->corePlugin())
mCoreInterface = qobject_cast<CoreInterface *>(mPluginManager->corePlugin()->instance());

// Set up the GUI

mGui->setupUi(this);
Expand Down Expand Up @@ -391,11 +397,8 @@ void MainWindow::closeEvent(QCloseEvent *pEvent)

bool canClose = true;

if (mPluginManager->corePlugin()) {
canClose = qobject_cast<CoreInterface *>(mPluginManager->corePlugin()->instance())->canClose();
// Note: if the Core plugin is loaded, then it means it supports the
// Core interface, so no need to check anything...
}
if (mCoreInterface)
canClose = mCoreInterface->canClose();

// Close ourselves, if possible

Expand Down Expand Up @@ -699,11 +702,8 @@ void MainWindow::loadSettings()
// settings
// Note: this is similar to initializePlugin() vs. pluginsInitialized()...

if (mPluginManager->corePlugin()) {
qobject_cast<CoreInterface *>(mPluginManager->corePlugin()->instance())->settingsLoaded(mPluginManager->loadedPlugins());
// Note: if the Core plugin is loaded, then it means it supports the
// Core interface, so no need to check anything...
}
if (mCoreInterface)
mCoreInterface->settingsLoaded(mPluginManager->loadedPlugins());

// Remove the File menu when on macOS, should no plugins be loaded
// Note: our File menu should only contain the Exit menu item, but on macOS
Expand Down Expand Up @@ -994,8 +994,8 @@ void MainWindow::handleArguments(const QStringList &pArguments)
arguments << stringFromPercentEncoding(argument);
}

if (!arguments.isEmpty() && mPluginManager->corePlugin())
qobject_cast<CoreInterface *>(mPluginManager->corePlugin()->instance())->handleArguments(arguments);
if (!arguments.isEmpty() && mCoreInterface)
mCoreInterface->handleArguments(arguments);

// Make sure that our status bar is shown/hidden, depending on its action's
// status
Expand Down
5 changes: 3 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

//==============================================================================

#include "guiinterface.h"
#include "plugin.h"

//==============================================================================
Expand All @@ -51,7 +50,7 @@ namespace OpenCOR {

//==============================================================================

class GuiInterface;
class CoreInterface;
class PluginManager;

//==============================================================================
Expand Down Expand Up @@ -94,6 +93,8 @@ class MainWindow : public QMainWindow
Plugins mLoadedPreferencesPlugins;
Plugins mLoadedWindowPlugins;

CoreInterface *mCoreInterface;

QString mRawLocale;

QTranslator mQtBaseTranslator;
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/miscellaneous/Core/src/centralwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,6 @@ void CentralWidget::reloadFile(int pIndex, bool pForce)
}
} else {
fileManagerInstance->reload(fileName);

fileManagerInstance->setModified(fileName, false);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/miscellaneous/Core/src/filemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ void FileManager::reload(const QString &pFileName)
file->reset();

emit fileReloaded(fileName);

// Reset our modified state and let people know about it, if needed

if (file->setModified(false))
emit fileModified(fileName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::finalize()
mGraphParametersContextMenu->clear();

mParameterActions.clear();

// Remove all our graphs' runs

foreach (GraphPanelWidget::GraphPanelPlotGraph *graph, mGraphs)
graph->removeRuns();
}

//==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ SimulationExperimentViewSimulationWidget::SimulationExperimentViewSimulationWidg
mGraphPanelsWidgetSizes(QIntList()),
mGraphPanelsWidgetSizesModified(false),
mCanUpdatePlotsForUpdatedGraphs(true),
mNeedReloadView(false),
mNeedUpdatePlots(false),
mOldDataSizes(QMap<GraphPanelWidget::GraphPanelPlotGraph *, quint64>())
{
Expand Down Expand Up @@ -887,7 +886,11 @@ void SimulationExperimentViewSimulationWidget::initialize(bool pReloadingView)

if (sedmlFileIssues.isEmpty() && combineArchiveIssues.isEmpty()) {
foreach (const CellMLSupport::CellmlFileIssue &issue,
runtime?runtime->issues():mSimulation->cellmlFile()->issues()) {
runtime?
runtime->issues():
mSimulation->cellmlFile()?
mSimulation->cellmlFile()->issues():
CellMLSupport::CellmlFileIssues()) {
information += QString(OutputTab+"<span"+OutputBad+"><strong>%1</strong> %2.</span>"+OutputBrLn).arg((issue.type() == CellMLSupport::CellmlFileIssue::Error)?tr("Error:"):tr("Warning:"))
.arg(issue.message());
}
Expand Down Expand Up @@ -1042,6 +1045,13 @@ void SimulationExperimentViewSimulationWidget::initialize(bool pReloadingView)
}

setUpdatesEnabled(true);

// Keep track of the initial size of our different graph panels
// Note: we do this through a single shot to give time to be certain that
// the GUI is ready and that the size of our different graph panels is
// therefore final...

QTimer::singleShot(0, this, &SimulationExperimentViewSimulationWidget::finalFurtherInitialize);
}

//==============================================================================
Expand Down Expand Up @@ -1229,40 +1239,14 @@ void SimulationExperimentViewSimulationWidget::fileModified()

//==============================================================================

void SimulationExperimentViewSimulationWidget::reloadView()
void SimulationExperimentViewSimulationWidget::fileReloaded()
{
// Reload ourselves, i.e. finalise and (re)initialise ourselves, meaning
// that we have effectively been closed and (re)opened
// The given file has been reloaded, so reload ourselves, i.e. finalise and
// (re)initialise ourselves, meaning that we have effectively been closed
// and (re)opened

finalize();
initialize(true);

mNeedReloadView = false;
}

//==============================================================================

void SimulationExperimentViewSimulationWidget::fileReloaded()
{
// The given file has been reloaded, so stop its current simulation

bool needReloadView = true;

mNeedReloadView = true;

if (mSimulation->stop()) {
needReloadView = false;
// Note: we don't need to reload ourselves since stopping the simulation
// will result in the stopped() signal being received and,
// therefore, the simulationStopped() slot being called, which is
// where we should reload ourselves since we cannot tell how long
// the signal/slot mechanism is going to take...
}

// Reload ourselves, if needed

if (needReloadView)
reloadView();
}

//==============================================================================
Expand Down Expand Up @@ -3023,6 +3007,19 @@ bool SimulationExperimentViewSimulationWidget::furtherInitialize()

//==============================================================================

void SimulationExperimentViewSimulationWidget::finalFurtherInitialize()
{
// The GUI is all ready, so we can initialise mGraphPanelsWidgetSizes, as
// well as mGraphPanelPropertiesModified and mGraphsPropertiesModified by
// calling checkGraphPanelsAndGraphs()

mGraphPanelsWidgetSizes = mContentsWidget->graphPanelsWidget()->sizes();

checkGraphPanelsAndGraphs();
}

//==============================================================================

void SimulationExperimentViewSimulationWidget::initializeGui(bool pValidSimulationEnvironment)
{
// Show/hide some widgets based on whether we have a valid simulation
Expand Down Expand Up @@ -3172,11 +3169,6 @@ void SimulationExperimentViewSimulationWidget::simulationStopped(qint64 pElapsed

mProgress = -1;

// Reload ourselves, if needed (see fileReloaded())

if (mNeedReloadView)
reloadView();

// Note: our simulation progress gets reset in resetSimulationProgress(),
// which is called by
// SimulationExperimentViewWidget::checkSimulationResults(). To reset
Expand Down Expand Up @@ -3229,17 +3221,10 @@ void SimulationExperimentViewSimulationWidget::resetSimulationProgress()
ResetDelay = 169
};

if (isVisible()) {
if (mNeedReloadView)
resetProgressBar();
else
QTimer::singleShot(ResetDelay, this, &SimulationExperimentViewSimulationWidget::resetProgressBar);
} else {
if (mNeedReloadView)
resetFileTabIcon();
else
QTimer::singleShot(ResetDelay, this, &SimulationExperimentViewSimulationWidget::resetFileTabIcon);
}
if (isVisible())
QTimer::singleShot(ResetDelay, this, &SimulationExperimentViewSimulationWidget::resetProgressBar);
else
QTimer::singleShot(ResetDelay, this, &SimulationExperimentViewSimulationWidget::resetFileTabIcon);
}

//==============================================================================
Expand Down Expand Up @@ -3721,20 +3706,6 @@ void SimulationExperimentViewSimulationWidget::updateGui(bool pCheckVisibility)
if (pCheckVisibility && !isVisible())
return;

// We need to update our GUI, which means that we can initialise
// mGraphPanelsWidgetSizes, if needed, as well as
// mGraphPanelPropertiesModified and mGraphsPropertiesModified by calling
// checkGraphPanelsAndGraphs()
// Note: we initialise mGraphPanelsWidgetSizes here since when we set our
// graph panels widget's sizes in furtherInitialize(), we don't end up
// with the final sizes since nothing is visible yet...

if (mGraphPanelsWidgetSizes.isEmpty()) {
mGraphPanelsWidgetSizes = mContentsWidget->graphPanelsWidget()->sizes();

checkGraphPanelsAndGraphs();
}

// Make sure that our graph panel and graphs widget's GUI is up to date

mContentsWidget->informationWidget()->graphPanelAndGraphsWidget()->updateGui();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,10 @@ class SimulationExperimentViewSimulationWidget : public Core::Widget

bool mCanUpdatePlotsForUpdatedGraphs;

bool mNeedReloadView;

bool mNeedUpdatePlots;

QMap<GraphPanelWidget::GraphPanelPlotGraph *, quint64> mOldDataSizes;

void reloadView();

void output(const QString &pMessage);

void updateSimulationMode();
Expand Down Expand Up @@ -369,6 +365,8 @@ private slots:
void checkSimulationProperties();
void checkSolversProperties();
void checkGraphPanelsAndGraphs();

void finalFurtherInitialize();
};

//==============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,17 @@ void SimulationExperimentViewWidget::fileModified(const QString &pFileName)

void SimulationExperimentViewWidget::fileSaved(const QString &pFileName)
{
// The given file has been saved, so consider it reloaded, but only if it
// has a corresponding widget that is invisible
// The given file has been saved, so reload its simulation and consider the
// file reloaded, but only if it has a corresponding widget that is
// invisible

QWidget *crtWidget = widget(pFileName);
SimulationExperimentViewSimulationWidget *crtSimulationWidget = simulationWidget(pFileName);

if (crtSimulationWidget && !crtSimulationWidget->isVisible()) {
crtSimulationWidget->simulation()->reload();

if (crtWidget && !crtWidget->isVisible())
fileReloaded(pFileName);
}
}

//==============================================================================
Expand Down
28 changes: 5 additions & 23 deletions src/plugins/support/CellMLSupport/src/cellmlfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ QString CellmlFileException::message() const
CellmlFile::CellmlFile(const QString &pFileName) :
StandardSupport::StandardFile(pFileName),
mRdfTriples(CellmlFileRdfTriples(this)),
mRuntime(new CellmlFileRuntime(this)),
mUpdated(false)
{
// Reset ourselves
Expand All @@ -106,10 +105,6 @@ CellmlFile::~CellmlFile()
// Reset ourselves

reset();

// Delete some internal objects

delete mRuntime;
}

//==============================================================================
Expand Down Expand Up @@ -141,7 +136,6 @@ void CellmlFile::reset()

mLoadingNeeded = true;
mFullInstantiationNeeded = true;
mRuntimeUpdateNeeded = true;
mDependenciesNeeded = true;

mImportContents.clear();
Expand Down Expand Up @@ -767,27 +761,15 @@ CellmlFileIssues CellmlFile::issues() const

CellmlFileRuntime * CellmlFile::runtime(bool pWithBusyWidget)
{
// Check whether the runtime needs to be updated

if (!mRuntimeUpdateNeeded)
return mRuntime;

// Load (but not reload!) ourselves, if needed

if (load()) {
// Make sure that our imports, if any, are fully instantiated
// Make sure that our imports, if any, are fully instantiated before
// returning our runtime

if (fullyInstantiateImports(mModel, mIssues, pWithBusyWidget)) {
// Now, we can return an updated version of our runtime

mRuntime->update();

mRuntimeUpdateNeeded = false;

return mRuntime;
} else {
return 0;
}
return fullyInstantiateImports(mModel, mIssues, pWithBusyWidget)?
new CellmlFileRuntime(this):
0;
} else {
return 0;
}
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/support/CellMLSupport/src/cellmlfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,8 @@ class CELLMLSUPPORT_EXPORT CellmlFile : public StandardSupport::StandardFile

CellmlFileIssues mIssues;

CellmlFileRuntime *mRuntime;

bool mLoadingNeeded;
bool mFullInstantiationNeeded;
bool mRuntimeUpdateNeeded;
bool mDependenciesNeeded;

QMap<QString, QString> mImportContents;
Expand Down

0 comments on commit 2952b2d

Please sign in to comment.