Skip to content

Commit f51d6d0

Browse files
committed
[Bug 6506] Fix regression to global watched variables
1 parent c87d432 commit f51d6d0

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

docs/notes/bugfix-6506.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix regression to watching global variables

engine/src/debug.cpp

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ void MCB_parsewatches(MCExecContext& ctxt, MCStringRef p_input)
559559
uindex_t t_input_length;
560560

561561
t_input_length = MCStringGetLength(p_input);
562+
563+
if (t_input_length == 0)
564+
return;
565+
562566
bool t_found;
563567
t_found = true;
564568

@@ -597,16 +601,12 @@ void MCB_parsewatches(MCExecContext& ctxt, MCStringRef p_input)
597601
if (t_success)
598602
t_success = MCStringDivideAtChar(*t_hname_tail, ',', kMCCompareExact, &t_vname, &t_express);
599603

600-
// AL-2015-07-31: [[ Bug 15822 ]] Don't abort parsing if a given line is not correctly formatted
601-
bool t_valid_watch;
602-
t_valid_watch = t_success;
603-
604-
MCObjectPtr t_object;
605-
// SN-2014-09-18: [[ Bug 13453 ]] With an empty string (no watchedVariables anymore), TryToResolveObject fails
606-
if (t_valid_watch)
607-
t_valid_watch = MCInterfaceTryToResolveObject(ctxt, *t_obj, t_object);
604+
MCObjectPtr t_object;
605+
bool t_resolved_object;
606+
if (t_success)
607+
t_resolved_object = MCInterfaceTryToResolveObject(ctxt, *t_obj, t_object);
608608

609-
if (t_valid_watch)
609+
if (t_success)
610610
{
611611
// OK-2010-01-14: [[Bug 6506]] - Allow globals in watchedVariables
612612
// If the object and handler are empty we assume its a global, otherwise
@@ -620,7 +620,11 @@ void MCB_parsewatches(MCExecContext& ctxt, MCStringRef p_input)
620620
if (t_new_watches != nil)
621621
{
622622
MCwatchedvars = t_new_watches;
623-
MCwatchedvars[MCnwatchedvars] . object = t_object . object;
623+
if (t_resolved_object)
624+
MCwatchedvars[MCnwatchedvars] . object = t_object . object;
625+
else
626+
MCwatchedvars[MCnwatchedvars] . object = nil;
627+
624628
if (MCStringGetLength(*t_hname) != 0)
625629
/* UNCHECKED */ MCNameCreate(*t_hname, MCwatchedvars[MCnwatchedvars] . handlername);
626630
else
@@ -648,37 +652,38 @@ bool MCB_unparsewatches(MCStringRef &r_watches)
648652
{
649653
for (uint32_t i = 0 ; i < MCnwatchedvars ; i++)
650654
{
651-
// OK-2010-01-14: [[Bug 6506]] - WatchedVariables support for globals
652-
if (MCwatchedvars[i] . object != NULL)
655+
MCAutoListRef t_watched_var;
656+
t_success = MCListCreateMutable(',', &t_watched_var);
657+
658+
if (t_success)
653659
{
654-
MCAutoListRef t_watched_var;
655-
t_success = MCListCreateMutable(',', &t_watched_var);
656-
657-
if (t_success)
660+
if (MCwatchedvars[i] . object != NULL)
658661
{
659662
MCAutoValueRef t_var_id;
660663
t_success = MCwatchedvars[i] . object -> names(P_LONG_ID, &t_var_id) &&
661-
MCListAppend(*t_watched_var, *t_var_id);
662-
}
663-
664-
if (t_success)
665-
{
666-
if (MCwatchedvars[i] . handlername == NULL)
667-
t_success = MCListAppend(*t_watched_var, kMCEmptyString);
668-
else
669-
t_success = MCListAppend(*t_watched_var, MCwatchedvars[i].handlername);
664+
MCListAppend(*t_watched_var, *t_var_id);
670665
}
671-
672-
if (t_success)
673-
t_success = MCListAppend(*t_watched_var, MCwatchedvars[i].varname);
666+
else
667+
t_success = MCListAppend(*t_watched_var, kMCEmptyString);
668+
}
669+
670+
if (t_success)
671+
{
672+
if (MCwatchedvars[i] . handlername == NULL)
673+
t_success = MCListAppend(*t_watched_var, kMCEmptyString);
674+
else
675+
t_success = MCListAppend(*t_watched_var, MCwatchedvars[i].handlername);
676+
}
677+
678+
if (t_success)
679+
t_success = MCListAppend(*t_watched_var, MCwatchedvars[i].varname);
674680

675-
// SN-2014-09-18: [[ Bug 13453 ]] A watched variable's expression is never nil
676-
if (t_success)
677-
t_success = MCListAppend(*t_watched_var, MCwatchedvars[i].expression);
681+
// SN-2014-09-18: [[ Bug 13453 ]] A watched variable's expression is never nil
682+
if (t_success)
683+
t_success = MCListAppend(*t_watched_var, MCwatchedvars[i].expression);
678684

679-
if (t_success)
680-
t_success = MCListAppend(*t_watches_list, *t_watched_var);
681-
}
685+
if (t_success)
686+
t_success = MCListAppend(*t_watches_list, *t_watched_var);
682687
}
683688
}
684689

0 commit comments

Comments
 (0)