Stop leaking scripting overlay

This commit is contained in:
GriffinR 2024-10-21 12:18:46 -04:00
parent b05f1d9ca1
commit 958b71afbb
4 changed files with 12 additions and 7 deletions

View file

@ -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();

View file

@ -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

View file

@ -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);
}
@ -50,6 +48,7 @@ Scripting::Scripting(MainWindow *mainWindow) {
}
Scripting::~Scripting() {
if (mainWindow) mainWindow->clearOverlay();
this->engine->setInterrupted(true);
qDeleteAll(this->imageCache);
delete this->engine;

View file

@ -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;
@ -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();
}