Skip to content

Commit

Permalink
Fix disappearing entity while scanning
Browse files Browse the repository at this point in the history
Just a simple guard clause to make sure that if an entity is mined away while we're scanning the site, we don't crash by trying to access something that doesn't exist.

Fixes #170
  • Loading branch information
narc0tiq committed Dec 18, 2024
1 parent 9c4491f commit 449372d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions resmon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -461,18 +461,20 @@ function resmon.scan_current_site(player_index)
local max_dist = settings.global["YARM-grow-limit"].value
for i = 1, to_scan do
local entity = table.remove(site.next_to_scan, 1)
local entity_position = entity.position
local surface = entity.surface
site.first_center = site.first_center or find_center(site.extents)

-- Look in every direction around this entity...
for _, dir in pairs(defines.direction) do
-- ...and if there's a resource, add it
local search_pos = shift_position(entity_position, dir)
if max_dist < 0 or util.distance(search_pos, site.first_center) < max_dist then
local found = find_resource_at(surface, search_pos)
if found and found.name == site.ore_type then
resmon.add_single_entity(player_index, found)
if entity and entity.valid then
local entity_position = entity.position
local surface = entity.surface
site.first_center = site.first_center or find_center(site.extents)

-- Look in every direction around this entity...
for _, dir in pairs(defines.direction) do
-- ...and if there's a resource, add it
local search_pos = shift_position(entity_position, dir)
if max_dist < 0 or util.distance(search_pos, site.first_center) < max_dist then
local found = find_resource_at(surface, search_pos)
if found and found.name == site.ore_type then
resmon.add_single_entity(player_index, found)
end
end
end
end
Expand Down

0 comments on commit 449372d

Please sign in to comment.