Remove crash bug when purging a dropped item in a wtrigger.
We're leveraging the lookup table, because it's a safer way to see if an object has been free'd than looking at the object itself (which while it may work may just as well fail). Fixes #83
This commit is contained in:
@@ -2994,12 +2994,18 @@ void init_lookup_table(void)
|
||||
}
|
||||
}
|
||||
|
||||
static struct char_data *find_char_by_uid_in_lookup_table(long uid)
|
||||
static struct lookup_table_t *find_element_by_uid_in_lookup_table(long uid)
|
||||
{
|
||||
int bucket = (int) (uid & (BUCKET_COUNT - 1));
|
||||
struct lookup_table_t *lt = &lookup_table[bucket];
|
||||
|
||||
for (;lt && lt->uid != uid ; lt = lt->next) ;
|
||||
return lt;
|
||||
}
|
||||
|
||||
static struct char_data *find_char_by_uid_in_lookup_table(long uid)
|
||||
{
|
||||
struct lookup_table_t *lt = find_element_by_uid_in_lookup_table(uid);
|
||||
|
||||
if (lt)
|
||||
return (struct char_data *)(lt->c);
|
||||
@@ -3010,10 +3016,7 @@ static struct char_data *find_char_by_uid_in_lookup_table(long uid)
|
||||
|
||||
static struct obj_data *find_obj_by_uid_in_lookup_table(long uid)
|
||||
{
|
||||
int bucket = (int) (uid & (BUCKET_COUNT - 1));
|
||||
struct lookup_table_t *lt = &lookup_table[bucket];
|
||||
|
||||
for (;lt && lt->uid != uid ; lt = lt->next) ;
|
||||
struct lookup_table_t *lt = find_element_by_uid_in_lookup_table(uid);
|
||||
|
||||
if (lt)
|
||||
return (struct obj_data *)(lt->c);
|
||||
@@ -3022,6 +3025,13 @@ static struct obj_data *find_obj_by_uid_in_lookup_table(long uid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int has_obj_by_uid_in_lookup_table(long uid)
|
||||
{
|
||||
struct lookup_table_t *lt = find_element_by_uid_in_lookup_table(uid);
|
||||
|
||||
return lt != NULL;
|
||||
}
|
||||
|
||||
void add_to_lookup_table(long uid, void *c)
|
||||
{
|
||||
int bucket = (int) (uid & (BUCKET_COUNT - 1));
|
||||
@@ -3054,9 +3064,7 @@ void remove_from_lookup_table(long uid)
|
||||
if (uid == 0)
|
||||
return;
|
||||
|
||||
for (;lt;lt = lt->next)
|
||||
if (lt->uid == uid)
|
||||
flt = lt;
|
||||
flt = find_element_by_uid_in_lookup_table(uid);
|
||||
|
||||
if (flt) {
|
||||
for (lt = &lookup_table[bucket];lt->next != flt;lt = lt->next)
|
||||
|
||||
Reference in New Issue
Block a user