1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Plugs a per-window memory leak.

While also ensuring proper OpenGL resource destruction.
This commit is contained in:
Thomas Harte 2020-06-22 20:32:44 -04:00
parent 13336b8ad5
commit 1875a03757
4 changed files with 19 additions and 2 deletions

View File

@ -17,7 +17,10 @@ int main(int argc, char *argv[])
// TODO: something with QCommandLineParser to accept a file to launch.
QApplication a(argc, argv);
MainWindow w;
w.show();
MainWindow *w = new MainWindow();
w->setAttribute(Qt::WA_DeleteOnClose);
w->show();
return a.exec();
}

View File

@ -51,6 +51,9 @@ MainWindow::~MainWindow() {
// to write to the audioOutput while it is being shut down.
timer.reset();
// Shut down the scan target while it still has a context for cleanup.
ui->openGLWidget->stop();
// Stop the audio output, and its thread.
if(audioOutput) {
audioThread.performAsync([this] {
@ -71,6 +74,7 @@ void MainWindow::closeEvent(QCloseEvent *event) {
// i.e. assume they were closing that document, not the application.
// if(mainWindowCount == 1 && machine) {
// MainWindow *const other = new MainWindow;
// other->setAttribute(Qt::WA_DeleteOnClose);
// other->show();
// }
QMainWindow::closeEvent(event);
@ -103,6 +107,7 @@ void MainWindow::createActions() {
MainWindow *other = new MainWindow;
other->tile(this);
other->setAttribute(Qt::WA_DeleteOnClose);
other->show();
});
fileMenu->addAction(newAct);
@ -119,6 +124,7 @@ void MainWindow::createActions() {
if(machine) {
MainWindow *const other = new MainWindow(fileName);
other->tile(this);
other->setAttribute(Qt::WA_DeleteOnClose);
other->show();
} else {
launchFile(fileName);

View File

@ -75,3 +75,9 @@ void ScanTargetWidget::setScanProducer(MachineTypes::ScanProducer *producer) {
this->producer = producer;
repaint();
}
void ScanTargetWidget::stop() {
makeCurrent();
scanTarget.reset();
isConnected = false;
}

View File

@ -18,6 +18,8 @@ class ScanTargetWidget : public QOpenGLWidget
// handed a suitable scan target as soon as one exists.
void setScanProducer(MachineTypes::ScanProducer *);
void stop();
protected:
void initializeGL() override;
void resizeGL(int w, int h) override;