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 eventTypeToString(Event::Type type);
static Event::Type eventTypeFromString(QString type);
static void clearIcons();
static void setIcons();
// protected attributes

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -44,6 +44,8 @@ Project::~Project()
{
clearMapCache();
clearTilesetCache();
clearMapLayouts();
clearEventGraphics();
}
void Project::initSignals() {
@ -362,6 +364,7 @@ bool Project::loadMapData(Map* map) {
heal->setRespawnNPC(loc.respawnNPC);
}
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();
mapLayoutsTable.clear();
}
bool Project::readMapLayouts() {
clearMapLayouts();
QString layoutsFilepath = projectConfig.getFilePath(ProjectFilePath::json_layouts);
QString fullFilepath = QString("%1/%2").arg(root).arg(layoutsFilepath);
@ -483,7 +491,7 @@ bool Project::readMapLayouts() {
.arg(layoutsLabel));
}
QList<QString> requiredFields = QList<QString>{
static const QList<QString> requiredFields = QList<QString>{
"id",
"name",
"width",
@ -2554,7 +2562,14 @@ void Project::setEventPixmap(Event *event, bool forceLoad) {
event->loadPixmap(this);
}
void Project::clearEventGraphics() {
qDeleteAll(eventGraphicsMap);
eventGraphicsMap.clear();
}
bool Project::readEventGraphics() {
clearEventGraphics();
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_pic_tables)
@ -2564,8 +2579,6 @@ bool Project::readEventGraphics() {
const QString pointersName = projectConfig.getIdentifier(ProjectIdentifier::symbol_obj_event_gfx_pointers);
QMap<QString, QString> pointerHash = parser.readNamedIndexCArray(pointersFilepath, pointersName);
qDeleteAll(eventGraphicsMap);
eventGraphicsMap.clear();
QStringList gfxNames = gfxDefines.keys();
// 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));
for (QString gfxName : gfxNames) {
EventGraphics * eventGraphics = new EventGraphics;
QString info_label = pointerHash[gfxName].replace("&", "");
if (!gfxInfos.contains(info_label))
continue;
const auto gfxInfoAttributes = gfxInfos[info_label];
auto eventGraphics = new EventGraphics;
eventGraphics->inanimate = ParseUtil::gameStringToBool(gfxInfoAttributes.value("inanimate"));
QString pic_label = gfxInfoAttributes.value("images");
QString dimensions_label = gfxInfoAttributes.value("oam");

View file

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

View file

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