Fix bad memory references in NewPatchDialog

This code was storing references to patch entries which could move around in memory if a patch was erased from the middle of a vector or if the vector itself was reallocated. Instead, NewPatchDialog maintains a separate copy of the patch entries which are committed back to the patch if the user accepts the changes.
This commit is contained in:
smurf3tte
2020-12-29 14:28:27 -08:00
parent f3b8a985e7
commit f4c579e720
2 changed files with 76 additions and 58 deletions

View File

@ -4,6 +4,7 @@
#pragma once
#include <memory>
#include <vector>
#include <QDialog>
@ -21,10 +22,13 @@ class QLineEdit;
class QVBoxLayout;
class QPushButton;
struct NewPatchEntry;
class NewPatchDialog : public QDialog
{
public:
explicit NewPatchDialog(QWidget* parent, PatchEngine::Patch& patch);
~NewPatchDialog() override;
private:
void CreateWidgets();
@ -33,7 +37,7 @@ private:
void accept() override;
QGroupBox* CreateEntry(PatchEngine::PatchEntry& entry);
QGroupBox* CreateEntry(const PatchEngine::PatchEntry& entry);
QLineEdit* m_name_edit;
QWidget* m_entry_widget;
@ -41,7 +45,7 @@ private:
QPushButton* m_add_button;
QDialogButtonBox* m_button_box;
std::vector<QLineEdit*> m_edits;
std::vector<std::unique_ptr<NewPatchEntry>> m_entries;
PatchEngine::Patch& m_patch;
};