Skip to content

Commit 1fee81a

Browse files
committed
fix annotations issue
1 parent 1779499 commit 1fee81a

6 files changed

Lines changed: 26 additions & 0 deletions

File tree

code/missioneditor/sexp_annotation_model.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ bool SexpAnnotationModel::isDefault(const event_annotation& ea)
126126
// Mutation
127127
// -----------------------------------------------------------------------
128128

129+
// Remove the annotation with the given key, if one exists.
130+
void SexpAnnotationModel::removeByKey(int key)
131+
{
132+
int idx = findByKey(key);
133+
if (idx >= 0) {
134+
m_annotations.erase(m_annotations.begin() + idx);
135+
}
136+
}
137+
129138
// Remove all annotations that have default values (no useful data).
130139
void SexpAnnotationModel::prune()
131140
{

code/missioneditor/sexp_annotation_model.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class SexpAnnotationModel {
5656
// Mutation
5757
// ---------------------------------------------------------------
5858

59+
// Remove the annotation with the given key, if one exists.
60+
void removeByKey(int key);
61+
5962
// Remove all annotations that are at default values.
6063
void prune();
6164

code/missioneditor/sexp_tree_model.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "missioneditor/sexp_tree_model.h"
2+
#include "missioneditor/sexp_annotation_model.h"
23

34
#include "parse/sexp.h"
45
#include "parse/sexp_container.h"
@@ -397,6 +398,11 @@ void SexpTreeModel::free_node2(int node)
397398
*modified = 1;
398399
tree_nodes[node].type = SEXPT_UNUSED;
399400
total_nodes--;
401+
402+
// Remove any annotation referencing this node so that if allocate_node()
403+
// reuses this slot, the new node won't inherit a stale annotation.
404+
if (annotation_model)
405+
annotation_model->removeByKey(node);
400406
if (tree_nodes[node].child != -1)
401407
free_node2(tree_nodes[node].child);
402408

code/missioneditor/sexp_tree_model.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "globalincs/flagset.h"
99
#include "globalincs/vmallocator.h"
1010

11+
class SexpAnnotationModel;
12+
1113
// -----------------------------------------------------------------------
1214
// SEXPT_* node type/status constants
1315
// -----------------------------------------------------------------------
@@ -440,6 +442,10 @@ class SexpTreeModel {
440442
// Model code sets *modified = 1 when tree data changes.
441443
int* modified;
442444

445+
// Optional annotation model — when set, free_node2() automatically removes
446+
// annotations referencing freed nodes to prevent stale annotation reuse.
447+
SexpAnnotationModel* annotation_model = nullptr;
448+
443449
// --- Tree navigation helpers ---
444450

445451
// Return the 0-based argument position of child_node among parent_node's children, or -1

fred2/eventeditor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ BOOL event_editor::OnInitDialog()
278278
// load event annotations into local model and apply comment icons
279279
m_annotation_model.loadFromGlobal(m_event_tree._model.tree_nodes, m_events, m_sig);
280280
m_event_tree.m_annotations = &m_annotation_model;
281+
m_event_tree._model.annotation_model = &m_annotation_model;
281282
for (auto &ea : m_annotation_model.annotations())
282283
{
283284
if (ea.node_index >= 0 && !ea.comment.empty())

qtfred/src/mission/dialogs/MissionEventsDialogModel.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ void MissionEventsDialogModel::initializeEvents()
166166
void MissionEventsDialogModel::initializeEventAnnotations()
167167
{
168168
m_annotation_model.loadFromGlobal(m_tree_model.tree_nodes, m_events, m_sig);
169+
m_tree_model.annotation_model = &m_annotation_model;
169170

170171
for (const auto& ea : m_annotation_model.annotations()) {
171172
if (ea.node_index >= 0) {

0 commit comments

Comments
 (0)