diff --git a/docs/notes/bugfix-21500.md b/docs/notes/bugfix-21500.md new file mode 100644 index 00000000000..ba3551da1f9 --- /dev/null +++ b/docs/notes/bugfix-21500.md @@ -0,0 +1 @@ +# Fix crash when ungrouping a group before calling quit diff --git a/engine/src/globals.cpp b/engine/src/globals.cpp index d2bad3c3286..809ed0a7672 100644 --- a/engine/src/globals.cpp +++ b/engine/src/globals.cpp @@ -1342,6 +1342,7 @@ int X_close(void) while (MCsavegroupptr != NULL) { MCControl *gptr = MCsavegroupptr->remove(MCsavegroupptr); + gptr -> removereferences(); delete gptr; } diff --git a/tests/lcs/core/engine/_ungroupandquit.livecodescript b/tests/lcs/core/engine/_ungroupandquit.livecodescript new file mode 100644 index 00000000000..2365b16fcfe --- /dev/null +++ b/tests/lcs/core/engine/_ungroupandquit.livecodescript @@ -0,0 +1,8 @@ +script "_ungroupandquit" +on startup + create button "one" + create button "two" + group button "one" and button "two" + ungroup the last group + quit 0 +end startup \ No newline at end of file diff --git a/tests/lcs/core/engine/engine.livecodescript b/tests/lcs/core/engine/engine.livecodescript index c4a1494063a..5ec52b2d272 100644 --- a/tests/lcs/core/engine/engine.livecodescript +++ b/tests/lcs/core/engine/engine.livecodescript @@ -501,3 +501,19 @@ wait 2 ticks TestAssert "the ticks change with time", the ticks - tTime >= 2 end TestTicks +on TestUngroupAndQuit + -- Bug 21500: run a subprocess in which we ungroup a group and + -- then quit, to test that it no longer crashes + local tStackToRun, tOptions + put the effective filename of me into tStackToRun + set the itemdelimiter to slash + if the environment is not "server" then + put "_ungroupandquit.livecodescript" into item -1 of tStackToRun + if the environment contains "command line" then + put "-ui" into tOptions + end if + end if + TestRunStack tOptions, tStackToRun + TestAssert "ungroup does not crash on quit", the result is empty +end TestUngroupAndQuit +