From 0235dde2684e2f18a1c8cb397fa5cf9849d217fb Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+ameligrana@users.noreply.github.com> Date: Sun, 25 Jan 2026 03:17:02 +0100 Subject: [PATCH 1/7] Add bounds check to is_alive function --- src/world.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/world.jl b/src/world.jl index fba3700a..4943d830 100644 --- a/src/world.jl +++ b/src/world.jl @@ -597,6 +597,7 @@ end Returns whether an [Entity](@ref) is alive. """ function is_alive(world::World, entity::Entity)::Bool + @boundscheck checkbounds(world._entity_pool.entities, entity._id) return _is_alive(world._entity_pool, entity) end From 96d2584c6c1a5e42185511294c9e73eb92f321d9 Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+ameligrana@users.noreply.github.com> Date: Sun, 25 Jan 2026 03:22:21 +0100 Subject: [PATCH 2/7] Optimize _is_alive function with @inbounds macro --- src/pool.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pool.jl b/src/pool.jl index 34b5aa7f..fa735689 100644 --- a/src/pool.jl +++ b/src/pool.jl @@ -42,7 +42,7 @@ function _recycle(p::_EntityPool, e::Entity) end function _is_alive(p::_EntityPool, e::Entity)::Bool - @inbounds return e._gen == p.entities[e._id]._gen + return @inbounds e._gen == p.entities[e._id]._gen end function _reset!(p::_EntityPool) From e3d55dedcd84fec104a6e2b948942a35839165df Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+ameligrana@users.noreply.github.com> Date: Sun, 25 Jan 2026 03:24:13 +0100 Subject: [PATCH 3/7] Add bounds check for entity ID in is_alive function --- src/world.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/world.jl b/src/world.jl index 4943d830..ab3e5445 100644 --- a/src/world.jl +++ b/src/world.jl @@ -597,7 +597,9 @@ end Returns whether an [Entity](@ref) is alive. """ function is_alive(world::World, entity::Entity)::Bool - @boundscheck checkbounds(world._entity_pool.entities, entity._id) + if entity._id > length(world._entity_pool.entities) + return false + end return _is_alive(world._entity_pool, entity) end From e1c0ad9ee65aa8ade4838cca51c6d546bc6dd212 Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+ameligrana@users.noreply.github.com> Date: Sun, 25 Jan 2026 03:51:04 +0100 Subject: [PATCH 4/7] Update world.jl --- src/world.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/world.jl b/src/world.jl index ab3e5445..fba3700a 100644 --- a/src/world.jl +++ b/src/world.jl @@ -597,9 +597,6 @@ end Returns whether an [Entity](@ref) is alive. """ function is_alive(world::World, entity::Entity)::Bool - if entity._id > length(world._entity_pool.entities) - return false - end return _is_alive(world._entity_pool, entity) end From 61efd5d4b5f1dda62a1181b91a4ab18e8f5186d3 Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+ameligrana@users.noreply.github.com> Date: Sun, 25 Jan 2026 03:51:38 +0100 Subject: [PATCH 5/7] Update pool.jl --- src/pool.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pool.jl b/src/pool.jl index fa735689..bf5003f5 100644 --- a/src/pool.jl +++ b/src/pool.jl @@ -42,7 +42,7 @@ function _recycle(p::_EntityPool, e::Entity) end function _is_alive(p::_EntityPool, e::Entity)::Bool - return @inbounds e._gen == p.entities[e._id]._gen + return e._gen == p.entities[e._id]._gen end function _reset!(p::_EntityPool) From d95dab9009f07f3c3696a0397a50aa218187e3d7 Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+ameligrana@users.noreply.github.com> Date: Sun, 25 Jan 2026 04:01:40 +0100 Subject: [PATCH 6/7] Update pool.jl --- src/pool.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pool.jl b/src/pool.jl index bf5003f5..ebf46bf4 100644 --- a/src/pool.jl +++ b/src/pool.jl @@ -42,7 +42,10 @@ function _recycle(p::_EntityPool, e::Entity) end function _is_alive(p::_EntityPool, e::Entity)::Bool - return e._gen == p.entities[e._id]._gen + if e._id > length(p.entities) + return false + end + return @inbounds e._gen == p.entities[e._id]._gen end function _reset!(p::_EntityPool) From 1c9b74a67a18f223d51ebe11354b060029ce672a Mon Sep 17 00:00:00 2001 From: Adriano Meligrana <68152031+ameligrana@users.noreply.github.com> Date: Sun, 25 Jan 2026 12:58:59 +0100 Subject: [PATCH 7/7] remove check --- src/pool.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pool.jl b/src/pool.jl index ebf46bf4..bf5003f5 100644 --- a/src/pool.jl +++ b/src/pool.jl @@ -42,10 +42,7 @@ function _recycle(p::_EntityPool, e::Entity) end function _is_alive(p::_EntityPool, e::Entity)::Bool - if e._id > length(p.entities) - return false - end - return @inbounds e._gen == p.entities[e._id]._gen + return e._gen == p.entities[e._id]._gen end function _reset!(p::_EntityPool)