Fix a bunch of memory leaks on startup->shutdown

This commit is contained in:
GriffinR 2024-09-11 13:09:03 -04:00
parent bb33d48ea1
commit a0ebae00c6
9 changed files with 37 additions and 10 deletions

View file

@ -187,6 +187,7 @@ public:
static QString eventGroupToString(Event::Group group); static QString eventGroupToString(Event::Group group);
static QString eventTypeToString(Event::Type type); static QString eventTypeToString(Event::Type type);
static Event::Type eventTypeFromString(QString type); static Event::Type eventTypeFromString(QString type);
static void clearIcons();
static void setIcons(); static void setIcons();
// protected attributes // protected attributes

View file

@ -89,6 +89,8 @@ public:
void clearMapCache(); void clearMapCache();
void clearTilesetCache(); void clearTilesetCache();
void clearMapLayouts();
void clearEventGraphics();
struct DataQualifiers struct DataQualifiers
{ {

View file

@ -17,7 +17,7 @@ class UpdatePromoter : public QDialog
public: public:
explicit UpdatePromoter(QWidget *parent, NetworkAccessManager *manager); explicit UpdatePromoter(QWidget *parent, NetworkAccessManager *manager);
~UpdatePromoter() {}; ~UpdatePromoter();
void checkForUpdates(); void checkForUpdates();
void updatePreferences(); void updatePreferences();

View file

@ -146,10 +146,13 @@ void Event::loadPixmap(Project *) {
this->pixmap = pixmap ? *pixmap : QPixmap(); this->pixmap = pixmap ? *pixmap : QPixmap();
} }
void Event::setIcons() { void Event::clearIcons() {
qDeleteAll(icons); qDeleteAll(icons);
icons.clear(); icons.clear();
}
void Event::setIcons() {
clearIcons();
const int w = 16; const int w = 16;
const int h = 16; const int h = 16;
static const QPixmap defaultIcons = QPixmap(":/images/Entities_16x16.png"); static const QPixmap defaultIcons = QPixmap(":/images/Entities_16x16.png");

View file

@ -1488,7 +1488,7 @@ void Editor::clearMap() {
bool Editor::displayMap() { bool Editor::displayMap() {
if (!scene) { if (!scene) {
scene = new QGraphicsScene; scene = new QGraphicsScene;
MapSceneEventFilter *filter = new MapSceneEventFilter(); MapSceneEventFilter *filter = new MapSceneEventFilter(scene);
scene->installEventFilter(filter); scene->installEventFilter(filter);
connect(filter, &MapSceneEventFilter::wheelZoom, this, &Editor::onWheelZoom); connect(filter, &MapSceneEventFilter::wheelZoom, this, &Editor::onWheelZoom);
scene->installEventFilter(this->map_ruler); scene->installEventFilter(this->map_ruler);

View file

@ -85,6 +85,9 @@ MainWindow::~MainWindow()
{ {
delete label_MapRulerStatus; delete label_MapRulerStatus;
delete editor; delete editor;
delete mapListProxyModel;
delete mapGroupItemsList;
delete mapListModel;
delete ui; delete ui;
} }
@ -1117,6 +1120,8 @@ void MainWindow::clearProjectUI() {
mapListModel->clear(); mapListModel->clear();
mapListIndexes.clear(); mapListIndexes.clear();
mapGroupItemsList->clear(); mapGroupItemsList->clear();
Event::clearIcons();
} }
void MainWindow::sortMapList() { void MainWindow::sortMapList() {

View file

@ -44,6 +44,8 @@ Project::~Project()
{ {
clearMapCache(); clearMapCache();
clearTilesetCache(); clearTilesetCache();
clearMapLayouts();
clearEventGraphics();
} }
void Project::initSignals() { void Project::initSignals() {
@ -362,6 +364,7 @@ bool Project::loadMapData(Map* map) {
heal->setRespawnNPC(loc.respawnNPC); heal->setRespawnNPC(loc.respawnNPC);
} }
map->events[Event::Group::Heal].append(heal); map->events[Event::Group::Heal].append(heal);
map->ownedEvents.append(heal);
} }
} }
@ -455,9 +458,14 @@ bool Project::loadMapLayout(Map* map) {
} }
} }
bool Project::readMapLayouts() { void Project::clearMapLayouts() {
qDeleteAll(mapLayouts);
mapLayouts.clear(); mapLayouts.clear();
mapLayoutsTable.clear(); mapLayoutsTable.clear();
}
bool Project::readMapLayouts() {
clearMapLayouts();
QString layoutsFilepath = projectConfig.getFilePath(ProjectFilePath::json_layouts); QString layoutsFilepath = projectConfig.getFilePath(ProjectFilePath::json_layouts);
QString fullFilepath = QString("%1/%2").arg(root).arg(layoutsFilepath); QString fullFilepath = QString("%1/%2").arg(root).arg(layoutsFilepath);
@ -483,7 +491,7 @@ bool Project::readMapLayouts() {
.arg(layoutsLabel)); .arg(layoutsLabel));
} }
QList<QString> requiredFields = QList<QString>{ static const QList<QString> requiredFields = QList<QString>{
"id", "id",
"name", "name",
"width", "width",
@ -2554,7 +2562,14 @@ void Project::setEventPixmap(Event *event, bool forceLoad) {
event->loadPixmap(this); event->loadPixmap(this);
} }
void Project::clearEventGraphics() {
qDeleteAll(eventGraphicsMap);
eventGraphicsMap.clear();
}
bool Project::readEventGraphics() { bool Project::readEventGraphics() {
clearEventGraphics();
fileWatcher.addPaths(QStringList() << root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx_pointers) fileWatcher.addPaths(QStringList() << root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx_pointers)
<< root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx_info) << root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx_info)
<< root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_pic_tables) << root + "/" + projectConfig.getFilePath(ProjectFilePath::data_obj_event_pic_tables)
@ -2564,8 +2579,6 @@ bool Project::readEventGraphics() {
const QString pointersName = projectConfig.getIdentifier(ProjectIdentifier::symbol_obj_event_gfx_pointers); const QString pointersName = projectConfig.getIdentifier(ProjectIdentifier::symbol_obj_event_gfx_pointers);
QMap<QString, QString> pointerHash = parser.readNamedIndexCArray(pointersFilepath, pointersName); QMap<QString, QString> pointerHash = parser.readNamedIndexCArray(pointersFilepath, pointersName);
qDeleteAll(eventGraphicsMap);
eventGraphicsMap.clear();
QStringList gfxNames = gfxDefines.keys(); QStringList gfxNames = gfxDefines.keys();
// The positions of each of the required members for the gfx info struct. // The positions of each of the required members for the gfx info struct.
@ -2584,14 +2597,13 @@ bool Project::readEventGraphics() {
QMap<QString, QString> graphicIncbins = parser.readCIncbinMulti(projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx)); QMap<QString, QString> graphicIncbins = parser.readCIncbinMulti(projectConfig.getFilePath(ProjectFilePath::data_obj_event_gfx));
for (QString gfxName : gfxNames) { for (QString gfxName : gfxNames) {
EventGraphics * eventGraphics = new EventGraphics;
QString info_label = pointerHash[gfxName].replace("&", ""); QString info_label = pointerHash[gfxName].replace("&", "");
if (!gfxInfos.contains(info_label)) if (!gfxInfos.contains(info_label))
continue; continue;
const auto gfxInfoAttributes = gfxInfos[info_label]; const auto gfxInfoAttributes = gfxInfos[info_label];
auto eventGraphics = new EventGraphics;
eventGraphics->inanimate = ParseUtil::gameStringToBool(gfxInfoAttributes.value("inanimate")); eventGraphics->inanimate = ParseUtil::gameStringToBool(gfxInfoAttributes.value("inanimate"));
QString pic_label = gfxInfoAttributes.value("images"); QString pic_label = gfxInfoAttributes.value("images");
QString dimensions_label = gfxInfoAttributes.value("oam"); QString dimensions_label = gfxInfoAttributes.value("oam");

View file

@ -19,7 +19,7 @@ NoScrollComboBox::NoScrollComboBox(QWidget *parent)
this->completer()->setFilterMode(Qt::MatchContains); this->completer()->setFilterMode(Qt::MatchContains);
static const QRegularExpression re("[^\\s]*"); static const QRegularExpression re("[^\\s]*");
QValidator *validator = new QRegularExpressionValidator(re); QValidator *validator = new QRegularExpressionValidator(re, this);
this->setValidator(validator); this->setValidator(validator);
} }

View file

@ -33,6 +33,10 @@ UpdatePromoter::UpdatePromoter(QWidget *parent, NetworkAccessManager *manager)
this->resetDialog(); this->resetDialog();
} }
UpdatePromoter::~UpdatePromoter() {
delete ui;
}
void UpdatePromoter::resetDialog() { void UpdatePromoter::resetDialog() {
this->button_Downloads->setEnabled(false); this->button_Downloads->setEnabled(false);