Fixed bugs with the add_object_to_store and remove_object_from_store
functions
This commit is contained in:
1 parent
149a1180d1
commit
fc94efcc46
1 file changed
+17
-1
+17
-1
@@ -64,7 +64,10 @@ ObjectID add_object_to_store(ObjectStore *os, void *object, EventHandlerPtr eh,
|
|||||||
if (os->deleted_count > 0) {
|
if (os->deleted_count > 0) {
|
||||||
id = (ObjectID)reuse_id((i32 *)os->reusable_ids, os->deleted_count);
|
id = (ObjectID)reuse_id((i32 *)os->reusable_ids, os->deleted_count);
|
||||||
os->deleted_count -= 1;
|
os->deleted_count -= 1;
|
||||||
|
|
||||||
|
if (id == os->count) {
|
||||||
os->count += 1;
|
os->count += 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
id = (os->count)++;
|
id = (os->count)++;
|
||||||
}
|
}
|
||||||
@@ -98,7 +101,20 @@ void remove_object_from_store(ObjectStore *os, ObjectID *id_ptr) {
|
|||||||
// count shouldn't be decremented since the deleted object would be in the
|
// count shouldn't be decremented since the deleted object would be in the
|
||||||
// middle, which means that the functions that loop over all objects in the
|
// middle, which means that the functions that loop over all objects in the
|
||||||
// store will not actually loop over everything
|
// store will not actually loop over everything
|
||||||
os->count -= 1;
|
|
||||||
|
u64 new_count = 0;
|
||||||
|
|
||||||
|
// Figure out how much we need to decrement the count. Since, a lot of
|
||||||
|
// objects may have been removed, the count needs to equal the last active
|
||||||
|
// object.
|
||||||
|
for (size_t i = id - 1; i >= 0; --i) {
|
||||||
|
if (os->object_ptrs[i]) {
|
||||||
|
new_count = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
os->count = new_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user