Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@

namespace mmp {

MainWindow* MainWindow::_instance = nullptr;

MainWindow::MainWindow()
{
_instance = this;

// Create model.
#if QT_VERSION >= 0x050500
QMessageLogger(__FILE__, __LINE__, nullptr).info() << "Video support: " <<
Expand Down Expand Up @@ -3617,11 +3621,10 @@ QString MainWindow::locateMediaFile(const QString &uri, bool isImage)
}

MainWindow* MainWindow::window() {
static MainWindow* instance = nullptr;
if (!instance) {
instance = new MainWindow;
if (!_instance) {
new MainWindow; // sets _instance first thing
}
return instance;
return _instance;
}

void MainWindow::updateCanvases()
Expand Down
9 changes: 9 additions & 0 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ public slots:

static MainWindow* window();

private:
// The singleton, published as soon as construction starts so that anything
// triggered from inside the constructor (e.g. restoring the output window in
// fullscreen repaints OutputGLCanvas, which asks for the main window) gets
// this instance instead of constructing a second one recursively.
static MainWindow* _instance;

public:

// Returns a short version of filename.
static QString strippedName(const QString &fullFileName);

Expand Down