Skip to content

Commit

Permalink
Fix a bunch of memory leaks on startup->shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Sep 11, 2024
1 parent bb33d48 commit a0ebae0
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/core/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class Event {
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
Expand Down
2 changes: 2 additions & 0 deletions include/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Project : public QObject

void clearMapCache();
void clearTilesetCache();
void clearMapLayouts();
void clearEventGraphics();

struct DataQualifiers
{
Expand Down
2 changes: 1 addition & 1 deletion include/ui/updatepromoter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UpdatePromoter : public QDialog

public:
explicit UpdatePromoter(QWidget *parent, NetworkAccessManager *manager);
~UpdatePromoter() {};
~UpdatePromoter();

void checkForUpdates();
void updatePreferences();
Expand Down
5 changes: 4 additions & 1 deletion src/core/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ MainWindow::~MainWindow()
{
delete label_MapRulerStatus;
delete editor;
delete mapListProxyModel;
delete mapGroupItemsList;
delete mapListModel;
delete ui;
}

Expand Down Expand Up @@ -1117,6 +1120,8 @@ void MainWindow::clearProjectUI() {
mapListModel->clear();
mapListIndexes.clear();
mapGroupItemsList->clear();

Event::clearIcons();
}

void MainWindow::sortMapList() {
Expand Down
24 changes: 18 additions & 6 deletions src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Project::~Project()
{
clearMapCache();
clearTilesetCache();
clearMapLayouts();
clearEventGraphics();
}

void Project::initSignals() {
Expand Down Expand Up @@ -362,6 +364,7 @@ bool Project::loadMapData(Map* map) {
heal->setRespawnNPC(loc.respawnNPC);
}
map->events[Event::Group::Heal].append(heal);
map->ownedEvents.append(heal);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -483,7 +491,7 @@ bool Project::readMapLayouts() {
.arg(layoutsLabel));
}

QList<QString> requiredFields = QList<QString>{
static const QList<QString> requiredFields = QList<QString>{
"id",
"name",
"width",
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/ui/noscrollcombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions src/ui/updatepromoter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ UpdatePromoter::UpdatePromoter(QWidget *parent, NetworkAccessManager *manager)
this->resetDialog();
}

UpdatePromoter::~UpdatePromoter() {
delete ui;
}

void UpdatePromoter::resetDialog() {
this->button_Downloads->setEnabled(false);

Expand Down

0 comments on commit a0ebae0

Please sign in to comment.