Skip to content

Commit

Permalink
Stop leaking scripting overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Oct 21, 2024
1 parent b05f1d9 commit 958b71a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public slots:
void on_mainTabBar_tabBarClicked(int index);
void on_mapViewTab_tabBarClicked(int index);
void onWarpBehaviorWarningClicked();
void clearOverlay();

private slots:
void on_action_Open_Project_triggered();
Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3081,6 +3081,11 @@ bool MainWindow::askToFixRegionMapEditor() {
return false;
}

void MainWindow::clearOverlay() {
if (ui->graphicsView_Map)
ui->graphicsView_Map->clearOverlayMap();
}

// Attempt to close any open sub-windows of the main window, giving each a chance to abort the process.
// Each of these windows is a widget with WA_DeleteOnClose set, so manually deleting them isn't necessary.
// Because they're tracked with QPointers nullifying them shouldn't be necessary either, but it seems the
Expand Down
3 changes: 1 addition & 2 deletions src/scriptapi/scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ void Scripting::stop() {
}

void Scripting::init(MainWindow *mainWindow) {
if (mainWindow->ui->graphicsView_Map)
mainWindow->ui->graphicsView_Map->clearOverlayMap();
Scripting::stop();
instance = new Scripting(mainWindow);
}
Expand All @@ -50,6 +48,7 @@ Scripting::Scripting(MainWindow *mainWindow) {
}

Scripting::~Scripting() {
if (mainWindow) mainWindow->clearOverlay();
this->engine->setInterrupted(true);
qDeleteAll(this->imageCache);
delete this->engine;
Expand Down
10 changes: 5 additions & 5 deletions src/ui/graphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ void GraphicsView::moveEvent(QMoveEvent *event) {
}

void MapView::drawForeground(QPainter *painter, const QRectF&) {
foreach (Overlay * overlay, this->overlayMap)
overlay->renderItems(painter);
for (auto i = this->overlayMap.constBegin(); i != this->overlayMap.constEnd(); i++) {
i.value()->renderItems(painter);
}

if (!editor) return;

Expand Down Expand Up @@ -56,9 +57,8 @@ void MapView::drawForeground(QPainter *painter, const QRectF&) {
}

void MapView::clearOverlayMap() {
foreach (Overlay * overlay, this->overlayMap) {
overlay->clearItems();
delete overlay;
for (auto i = this->overlayMap.constBegin(); i != this->overlayMap.constEnd(); i++) {
delete i.value();
}
this->overlayMap.clear();
}
Expand Down

0 comments on commit 958b71a

Please sign in to comment.