mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-22 12:31:10 +00:00
[ecs] Handle indices beyond the subpools
It turns out that the bsearch bug was hiding incorrect handling of indices in the subpool beyond the last tracked subpool. In which case, a correctly working bsearch correctly fails to find the range, but the search can be skipped entirely.
This commit is contained in:
parent
76ac446156
commit
28226ac75c
1 changed files with 4 additions and 2 deletions
|
@ -89,6 +89,7 @@ range_cmp (const void *_key, const void *_range, void *_subpool)
|
||||||
const uint32_t *range = _range;
|
const uint32_t *range = _range;
|
||||||
ecs_subpool_t *subpool = _subpool;
|
ecs_subpool_t *subpool = _subpool;
|
||||||
|
|
||||||
|
// range is the first index for the next subpool range
|
||||||
if (*key >= *range) {
|
if (*key >= *range) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -117,8 +118,9 @@ Ent_RemoveComponent (uint32_t ent, uint32_t comp, ecs_registry_t *registry)
|
||||||
if (ind < pool->count && pool->dense[ind] == ent) {
|
if (ind < pool->count && pool->dense[ind] == ent) {
|
||||||
uint32_t last = pool->count - 1;
|
uint32_t last = pool->count - 1;
|
||||||
Component_DestroyElements (c, pool->data, ind, 1);
|
Component_DestroyElements (c, pool->data, ind, 1);
|
||||||
if (subpool->num_ranges - subpool->available) {
|
uint32_t range_count = subpool->num_ranges - subpool->available;
|
||||||
uint32_t range_count = subpool->num_ranges - subpool->available;
|
// if ind >= the last range, then it is outside the subpools
|
||||||
|
if (range_count && ind < subpool->ranges[range_count - 1]) {
|
||||||
uint32_t *range = find_range (subpool, ind);
|
uint32_t *range = find_range (subpool, ind);
|
||||||
while (range - subpool->ranges < range_count) {
|
while (range - subpool->ranges < range_count) {
|
||||||
uint32_t end = --*range;
|
uint32_t end = --*range;
|
||||||
|
|
Loading…
Reference in a new issue