Skip to content

Commit a07bc8c

Browse files
committed
Merge branch 'bugfix-13167' into develop
2 parents 8c41e84 + 1ed1c9b commit a07bc8c

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

docs/notes/bugfix-13167.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Crash when stack loses focus.

engine/src/card.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,10 @@ void MCCard::kfocus()
232232
if (oldkfocused != NULL && kfocused == NULL)
233233
{
234234
kfocused = oldkfocused;
235+
// MW-2014-08-12: [[ Bug 13167 ]] Sync the view focus before the engine state
236+
// (otherwise the engine state can change due to script).
237+
MCscreen -> controlgainedfocus(getstack(), kfocused -> getid());
235238
kfocused->getref()->kfocus();
236-
MCscreen -> controlgainedfocus(getstack(), kfocused -> getid());
237239
}
238240
if (kfocused == NULL)
239241
kfocusnext(True);
@@ -269,8 +271,10 @@ Boolean MCCard::kfocusnext(Boolean top)
269271
if (oldkfocused->getref() == MCactivefield
270272
&& !MCactivefield->getflag(F_LIST_BEHAVIOR))
271273
MCactivefield->unselect(False, True);
272-
oldkfocused->getref()->kunfocus();
274+
// MW-2014-08-12: [[ Bug 13167 ]] Sync the view focus before the engine state
275+
// (otherwise the engine state can change due to script).
273276
MCscreen -> controllostfocus(getstack(), oldkfocused -> getid());
277+
oldkfocused->getref()->kunfocus();
274278
if (oldkfocused == NULL)
275279
return False;
276280
}
@@ -326,8 +330,10 @@ Boolean MCCard::kfocusprev(Boolean bottom)
326330
if (oldkfocused->getref() == MCactivefield
327331
&& !MCactivefield->getflag(F_LIST_BEHAVIOR))
328332
MCactivefield->unselect(False, True);
329-
oldkfocused->getref()->kunfocus();
333+
// MW-2014-08-12: [[ Bug 13167 ]] Sync the view focus before the engine state
334+
// (otherwise the engine state can change due to script).
330335
MCscreen -> controllostfocus(getstack(), oldkfocused -> getid());
336+
oldkfocused->getref()->kunfocus();
331337
if (oldkfocused == NULL)
332338
return False;
333339
}
@@ -357,10 +363,10 @@ void MCCard::kunfocus()
357363
{
358364
oldkfocused = kfocused;
359365
kfocused = NULL;
366+
// MW-2014-08-12: [[ Bug 13167 ]] Sync the view focus before the engine state
367+
// (otherwise the engine state can change due to script).
368+
MCscreen -> controllostfocus(getstack(), oldkfocused -> getid());
360369
oldkfocused->getref()->kunfocus();
361-
// PM-2014-04-03: [[Bug 12056]] Make sure oldkfocused is not NULL, or else IDE crashes
362-
if (oldkfocused != NULL)
363-
MCscreen -> controllostfocus(getstack(), oldkfocused -> getid());
364370
}
365371
else
366372
{
@@ -1394,8 +1400,10 @@ void MCCard::kfocusset(MCControl *target)
13941400
if (tkfocused != NULL && tkfocused->getref() != target)
13951401
{
13961402
kfocused = NULL;
1403+
// MW-2014-08-12: [[ Bug 13167 ]] Sync the view focus before the engine state
1404+
// (otherwise the engine state can change due to script).
1405+
MCscreen -> controllostfocus(getstack(), tkfocused -> getid());
13971406
tkfocused->getref()->kunfocus();
1398-
MCscreen -> controllostfocus(getstack(), tkfocused -> getid());
13991407
}
14001408
if (kfocused != NULL)
14011409
return;
@@ -1405,11 +1413,10 @@ void MCCard::kfocusset(MCControl *target)
14051413
{
14061414
if (kfocused->getref()->kfocusset(target))
14071415
{
1416+
// MW-2014-08-12: [[ Bug 13167 ]] Sync the view focus before the engine state
1417+
// (otherwise the engine state can change due to script).
1418+
MCscreen -> controlgainedfocus(getstack(), kfocused -> getid());
14081419
kfocused->getref()->kfocus();
1409-
// MW-2014-08-06: [[ Bug 13072 ]] Only invoke this if kfocused is still non-nil
1410-
// (if focusing the control refocuses, it will be nil).
1411-
if (kfocused != nil)
1412-
MCscreen -> controlgainedfocus(getstack(), kfocused -> getid());
14131420

14141421
// OK-2009-04-29: [[Bug 8013]] - Its possible that kfocus() can set kfocused to NULL if the
14151422
// user handles the message and does something to unfocus the object (e.g. select empty)

0 commit comments

Comments
 (0)