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

Commit 41fe259

Browse files
committed
[[ Bug 22130 ]] Disable deleted object pool creation whilst debugging
This patch adds a 'freeze' count to the deleted object pool logic. When the current pool is frozen, no new pools will be created until it is thawed again. This means that all objects that are deleted during that period are accumulated in the frozen pool. This ability is used inside MCB_prepmessage, which is the handler which causes the engine to enter debug mode and send a message. Doing this prevents corruption of the deleted object pools stack which appears to occur when the script editor manipulates menus in the context of a debug-related message. As the use of freezing the current object pool is only used in this one place it has no effect on normal running code, only on code which runs in the context of a debug-related message.
1 parent b5dbb62 commit 41fe259

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

docs/notes/bugfix-22130.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Improve stability of breakpoint manipulation in the S/E whilst debugging

engine/src/debug.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ void MCB_prepmessage(MCExecContext &ctxt, MCNameRef mess, uint2 line, uint2 pos,
284284
p3.setnext(&p4);
285285
p4.setvalueref_argument(p_info);
286286
}
287-
MCB_message(ctxt, mess, &p1);
287+
MCDeletedObjectsFreezePool();
288+
MCB_message(ctxt, mess, &p1);
289+
MCDeletedObjectsThawPool();
288290
if (id != 0)
289291
MCeerror->clear();
290292
if (added)

engine/src/object.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5519,6 +5519,7 @@ struct MCDeletedObjectPool
55195519
static MCDeletedObjectPool *MCsparedeletedobjectpool = nil;
55205520
static MCDeletedObjectPool *MCdeletedobjectpool = nil;
55215521
static MCDeletedObjectPool *MCrootdeletedobjectpool = nil;
5522+
static uint32_t MCdeletedobjectpoolfreezedepth = 0;
55225523

55235524
static bool MCDeletedObjectPoolCreate(MCDeletedObjectPool*& r_pool)
55245525
{
@@ -5604,8 +5605,22 @@ void MCDeletedObjectsTeardown(void)
56045605
}
56055606
}
56065607

5608+
void MCDeletedObjectsFreezePool(void)
5609+
{
5610+
MCdeletedobjectpoolfreezedepth += 1;
5611+
}
5612+
5613+
void MCDeletedObjectsThawPool(void)
5614+
{
5615+
MCdeletedobjectpoolfreezedepth -= 1;
5616+
}
5617+
56075618
void MCDeletedObjectsEnterWait(bool p_dispatching)
56085619
{
5620+
// If the current pool is frozen, do nothing
5621+
if (MCdeletedobjectpoolfreezedepth > 0)
5622+
return;
5623+
56095624
// If this isn't a dispatching wait, then no objects can be created.
56105625
if (!p_dispatching)
56115626
return;
@@ -5632,6 +5647,10 @@ void MCDeletedObjectsEnterWait(bool p_dispatching)
56325647

56335648
void MCDeletedObjectsLeaveWait(bool p_dispatching)
56345649
{
5650+
// If the current pool is frozen, do nothing
5651+
if (MCdeletedobjectpoolfreezedepth > 0)
5652+
return;
5653+
56355654
// If this isn't a dispatching wait, then no objects can be created.
56365655
if (!p_dispatching)
56375656
return;

engine/src/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ struct MCExecValue;
506506
struct MCDeletedObjectPool;
507507
void MCDeletedObjectsSetup(void);
508508
void MCDeletedObjectsTeardown(void);
509+
void MCDeletedObjectsFreezePool(void);
510+
void MCDeletedObjectsThawPool(void);
509511
void MCDeletedObjectsEnterWait(bool p_dispatching);
510512
void MCDeletedObjectsLeaveWait(bool p_dispatching);
511513
void MCDeletedObjectsOnObjectCreated(MCObject *object);

0 commit comments

Comments
 (0)