Skip to content

Commit 8844ac4

Browse files
author
livecodeali
committed
[[ Bug 16875 ]] Don't modify card controls if group command fails
1 parent 65ecf0e commit 8844ac4

2 files changed

Lines changed: 56 additions & 46 deletions

File tree

docs/notes/bugfix-16875.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Don't modify card controls if group command fails

engine/src/exec-interface.cpp

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,57 +1962,66 @@ void MCInterfaceExecRevert(MCExecContext& ctxt)
19621962

19631963
void MCInterfaceExecGroupControls(MCExecContext& ctxt, MCObjectPtr *p_controls, uindex_t p_control_count)
19641964
{
1965+
if (p_control_count == 0)
1966+
return;
1967+
19651968
// MW-2013-06-20: [[ Bug 10863 ]] Make sure all objects have this parent, after
19661969
// the first object has been resolved.
19671970
MCObject *t_required_parent;
19681971
t_required_parent = nil;
1972+
1973+
MCCard *t_card = nil;
1974+
MCControl *controls = nil;
1975+
MCObject *t_this_parent = nil;
1976+
MCControl *cptr = nil;
19691977

1970-
if (p_control_count != 0)
1971-
{
1972-
MCCard *t_card = nil;
1973-
MCControl *controls = nil;
1974-
MCObject *t_this_parent = nil;
1975-
for (uindex_t i = 0; i < p_control_count; ++i)
1976-
{
1977-
t_this_parent = (p_controls[i] . object) -> getparent();
1978-
if (t_this_parent == nil || t_this_parent -> gettype() != CT_CARD)
1979-
{
1980-
ctxt . LegacyThrow(EE_GROUP_NOTGROUPABLE);
1981-
return;
1982-
}
1983-
MCControl *cptr = (MCControl *)p_controls[i] . object;
1984-
// MW-2011-01-21: Make sure we don't try and group shared groups
1985-
if (cptr -> gettype() == CT_GROUP && static_cast<MCGroup *>(cptr) -> isshared())
1986-
{
1987-
ctxt . LegacyThrow(EE_GROUP_NOBG);
1988-
return;
1989-
}
1990-
1991-
// MW-2013-06-20: [[ Bug 10863 ]] Take the parent of the first object for
1992-
// future comparisons.
1993-
if (t_required_parent == nil)
1994-
t_required_parent = t_this_parent;
1995-
1996-
// MERG-2013-05-07: [[ Bug 10863 ]] Make sure all objects have the same
1997-
// parent.
1998-
if (t_this_parent != t_required_parent)
1999-
{
2000-
ctxt . LegacyThrow(EE_GROUP_DIFFERENTPARENT);
2001-
return;
2002-
}
2003-
2004-
t_card = cptr->getcard(p_controls[i] . part_id);
2005-
t_card -> removecontrol(cptr, False, True);
2006-
cptr -> getstack() -> removecontrol(cptr);
2007-
cptr -> appendto(controls);
2008-
}
2009-
MCGroup *gptr;
2010-
if (MCsavegroupptr == NULL)
2011-
gptr = (MCGroup *)MCtemplategroup->clone(False, OP_NONE, false);
2012-
else
2013-
gptr = (MCGroup *)MCsavegroupptr->remove(MCsavegroupptr);
2014-
gptr->makegroup(controls, t_card);
2015-
}
1978+
uindex_t i;
1979+
for (i = 0; i < p_control_count; ++i)
1980+
{
1981+
t_this_parent = (p_controls[i] . object) -> getparent();
1982+
if (t_this_parent == nil || t_this_parent -> gettype() != CT_CARD)
1983+
{
1984+
ctxt . LegacyThrow(EE_GROUP_NOTGROUPABLE);
1985+
return;
1986+
}
1987+
1988+
cptr = (MCControl *)p_controls[i] . object;
1989+
// MW-2011-01-21: Make sure we don't try and group shared groups
1990+
if (cptr -> gettype() == CT_GROUP && static_cast<MCGroup *>(cptr) -> isshared())
1991+
{
1992+
ctxt . LegacyThrow(EE_GROUP_NOBG);
1993+
return;
1994+
}
1995+
1996+
// MW-2013-06-20: [[ Bug 10863 ]] Take the parent of the first object for
1997+
// future comparisons.
1998+
if (t_required_parent == nil)
1999+
t_required_parent = t_this_parent;
2000+
2001+
// MERG-2013-05-07: [[ Bug 10863 ]] Make sure all objects have the same
2002+
// parent.
2003+
if (t_this_parent != t_required_parent)
2004+
{
2005+
ctxt . LegacyThrow(EE_GROUP_DIFFERENTPARENT);
2006+
return;
2007+
}
2008+
}
2009+
2010+
// If we made it this far, the controls are ok to group.
2011+
for (i = 0; i < p_control_count; ++i)
2012+
{
2013+
t_card = cptr->getcard(p_controls[i] . part_id);
2014+
t_card -> removecontrol(cptr, False, True);
2015+
cptr -> getstack() -> removecontrol(cptr);
2016+
cptr -> appendto(controls);
2017+
}
2018+
2019+
MCGroup *gptr;
2020+
if (MCsavegroupptr == NULL)
2021+
gptr = (MCGroup *)MCtemplategroup->clone(False, OP_NONE, false);
2022+
else
2023+
gptr = (MCGroup *)MCsavegroupptr->remove(MCsavegroupptr);
2024+
gptr->makegroup(controls, t_card);
20162025
}
20172026

20182027
void MCInterfaceExecGroupSelection(MCExecContext& ctxt)

0 commit comments

Comments
 (0)