summaryrefslogtreecommitdiff
path: root/src/map/map.hpp
diff options
context:
space:
mode:
authorFreeyorp <TheFreeYorp+git@gmail.com>2024-04-29 10:15:51 +0000
committerFreeyorp <TheFreeYorp+git@gmail.com>2024-04-29 12:43:39 +0000
commit9d00c99cd0c636aa5a6c25677d334d455cd9195f (patch)
treec4e4956aa42b17b7085924e3623db45f29959f5e /src/map/map.hpp
parentbafec99026144d807bb140b6daf86853c4603e51 (diff)
downloadtmwa-9d00c99cd0c636aa5a6c25677d334d455cd9195f.tar.gz
tmwa-9d00c99cd0c636aa5a6c25677d334d455cd9195f.tar.bz2
tmwa-9d00c99cd0c636aa5a6c25677d334d455cd9195f.tar.xz
tmwa-9d00c99cd0c636aa5a6c25677d334d455cd9195f.zip
npc_destroy: Defer NPC destruction via timer
055-1 _nodes.txt will call `destroy;` from within OnInit, that is during an iteration of the global `ev_db`. Previously, concurrent modification invalidated this iteration, resulting in a crash. This still nullifes `oid`, dequeues all timers, and effectively calls `builtin_end`. `npc_data::deletion_pending` is extended to include a third state. In addition to no deletion happening, and indicating when `npc_free` is currently on the stack, it now also tracks whether the NPC is about to be deleted by a timer. This means that an NPC which is about to be deleted is still blocked from triggering new events, much like an NPC actively being deleted would. Starting or continuing an NPC dialog with an NPC that does not, or is about to no longer exist, is now also blocked.
Diffstat (limited to 'src/map/map.hpp')
-rw-r--r--src/map/map.hpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/map/map.hpp b/src/map/map.hpp
index 7cf43d5..56d07a5 100644
--- a/src/map/map.hpp
+++ b/src/map/map.hpp
@@ -360,7 +360,11 @@ struct npc_data : block_list
Opt0 option;
short flag;
- bool deletion_pending;
+ enum {
+ NOT_DELETING = 0,
+ DELETION_QUEUED = 1,
+ DELETION_ACTIVE = 2
+ } deletion_pending;
Array<Timer, MAX_EVENTTIMER> eventtimer;