Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
1 change: 1 addition & 0 deletions docs/notes/bugfix-22130.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Improve stability of breakpoint manipulation in the S/E whilst debugging
4 changes: 3 additions & 1 deletion engine/src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ void MCB_prepmessage(MCExecContext &ctxt, MCNameRef mess, uint2 line, uint2 pos,
p3.setnext(&p4);
p4.setvalueref_argument(p_info);
}
MCB_message(ctxt, mess, &p1);
MCDeletedObjectsFreezePool();
MCB_message(ctxt, mess, &p1);
MCDeletedObjectsThawPool();
if (id != 0)
MCeerror->clear();
if (added)
Expand Down
19 changes: 19 additions & 0 deletions engine/src/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5523,6 +5523,7 @@ struct MCDeletedObjectPool
static MCDeletedObjectPool *MCsparedeletedobjectpool = nil;
static MCDeletedObjectPool *MCdeletedobjectpool = nil;
static MCDeletedObjectPool *MCrootdeletedobjectpool = nil;
static uint32_t MCdeletedobjectpoolfreezedepth = 0;

static bool MCDeletedObjectPoolCreate(MCDeletedObjectPool*& r_pool)
{
Expand Down Expand Up @@ -5608,8 +5609,22 @@ void MCDeletedObjectsTeardown(void)
}
}

void MCDeletedObjectsFreezePool(void)
{
MCdeletedobjectpoolfreezedepth += 1;
}

void MCDeletedObjectsThawPool(void)
{
MCdeletedobjectpoolfreezedepth -= 1;
}

void MCDeletedObjectsEnterWait(bool p_dispatching)
{
// If the current pool is frozen, do nothing
if (MCdeletedobjectpoolfreezedepth > 0)
return;

// If this isn't a dispatching wait, then no objects can be created.
if (!p_dispatching)
return;
Expand All @@ -5636,6 +5651,10 @@ void MCDeletedObjectsEnterWait(bool p_dispatching)

void MCDeletedObjectsLeaveWait(bool p_dispatching)
{
// If the current pool is frozen, do nothing
if (MCdeletedobjectpoolfreezedepth > 0)
return;

// If this isn't a dispatching wait, then no objects can be created.
if (!p_dispatching)
return;
Expand Down
2 changes: 2 additions & 0 deletions engine/src/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ struct MCExecValue;
struct MCDeletedObjectPool;
void MCDeletedObjectsSetup(void);
void MCDeletedObjectsTeardown(void);
void MCDeletedObjectsFreezePool(void);
void MCDeletedObjectsThawPool(void);
void MCDeletedObjectsEnterWait(bool p_dispatching);
void MCDeletedObjectsLeaveWait(bool p_dispatching);
void MCDeletedObjectsOnObjectCreated(MCObject *object);
Expand Down