Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 9681cf0

Browse files
committed
[[ Bug 19313 ]] Set fdata paragraphs' parent while saving
If a field on a cloned card or stack is unopened, its fdata paragraphs may never be assigned a parent. Set the parent before saving, so that parent font atts can be accessed and preventing a crash.
1 parent 53ad88e commit 9681cf0

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

docs/notes/bugfix-19313.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix crash when saving field with fdata

engine/src/button.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3683,7 +3683,7 @@ IO_stat MCButton::save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_
36833683
{
36843684
do
36853685
{
3686-
if ((stat = tptr->save(stream, OT_BDATA, p_part, p_version)) != IO_NORMAL)
3686+
if ((stat = tptr->save(stream, OT_BDATA, p_part, nil, p_version)) != IO_NORMAL)
36873687
return stat;
36883688
tptr = (MCCdata *)tptr->next();
36893689
}

engine/src/cdata.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ IO_stat MCCdata::load(IO_handle stream, MCObject *parent, uint32_t version)
164164
return IO_NORMAL;
165165
}
166166

167-
IO_stat MCCdata::save(IO_handle stream, Object_type type, uint4 p_part, uint32_t p_version)
167+
IO_stat MCCdata::save(IO_handle stream, Object_type type, uint4 p_part, MCObject *p_parent, uint32_t p_version)
168168
{
169169
IO_stat stat;
170170

@@ -191,10 +191,16 @@ IO_stat MCCdata::save(IO_handle stream, Object_type type, uint4 p_part, uint32_t
191191
}
192192
else
193193
{
194+
// Ensure field's saved MCCdata paragraphs have a parent
195+
if (p_parent != nil)
196+
MCAssert(p_parent -> gettype() == CT_FIELD);
197+
194198
MCParagraph *tptr = (MCParagraph *)data;
195199
if (tptr != NULL)
196200
do
197201
{
202+
if (p_parent != nil)
203+
tptr -> setparent(static_cast<MCField *>(p_parent));
198204
if ((stat = tptr->save(stream, p_part, p_version)) != IO_NORMAL)
199205
return stat;
200206
tptr = (MCParagraph *)tptr->next();

engine/src/cdata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class MCCdata : public MCDLlist
3535
MCCdata(const MCCdata &fref, MCField* p_new_owner);
3636
~MCCdata();
3737
IO_stat load(IO_handle stream, MCObject *parent, uint32_t version);
38-
IO_stat save(IO_handle stream, Object_type type, uint4 p_part, uint32_t p_version);
38+
IO_stat save(IO_handle stream, Object_type type, uint4 p_part, MCObject *parent, uint32_t p_version);
3939
uint4 getid();
4040
void setid(uint4 newid);
4141
MCParagraph *getparagraphs();

engine/src/field.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,15 +2634,15 @@ IO_stat MCField::save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_t
26342634
MCCdata *tptr;
26352635
tptr = getcarddata(fdata, 0, False);
26362636
if (tptr != NULL)
2637-
if ((stat = tptr -> save(stream, OT_FDATA, 0, p_version)) != IO_NORMAL)
2637+
if ((stat = tptr -> save(stream, OT_FDATA, 0, this, p_version)) != IO_NORMAL)
26382638
return stat;
26392639
}
26402640
else
26412641
{
26422642
MCCdata *tptr = fdata;
26432643
do
26442644
{
2645-
if ((stat = tptr->save(stream, OT_FDATA, p_part, p_version)) != IO_NORMAL)
2645+
if ((stat = tptr->save(stream, OT_FDATA, p_part, this, p_version)) != IO_NORMAL)
26462646
return stat;
26472647
tptr = tptr->next();
26482648
}

0 commit comments

Comments
 (0)