From c876179024c778af39baf35787f11c2c8d17c6af Mon Sep 17 00:00:00 2001 From: Megaf Date: Sun, 22 Jun 2014 20:42:26 -0300 Subject: [PATCH] api.lua:5: attempt to index local 'pos' (a nil value) This was suggested by RBA to fix the follow. ``` 18:43:28: ACTION[ServerThread]: Sofia punches object -27616: LuaEntitySAO at (13.9607,18.7545,-77.3249) 18:43:41: ERROR[main]: ERROR: An unhandled exception occurred: /home/minetest/Server/bin/../mods/areas/api.lua:5: attempt to index local 'pos' (a nil value) 18:43:41: ERROR[main]: stack traceback: 18:43:41: ERROR[main]: /home/minetest/Server/bin/../mods/areas/api.lua:5: in function 'getAreasAtPos' 18:43:41: ERROR[main]: /home/minetest/Server/bin/../mods/areas/legacy.lua:101: in function 'HasOwner' 18:43:41: ERROR[main]: ...inetest/Server/bin/../mods/plantlife/plants_lib/init.lua:448: in function 'node_is_owned' 18:43:41: ERROR[main]: ...etest/Server/bin/../mods/plantlife/flowers_plus/init.lua:97: in function <...etest/Server/bin/../mods/plantlife/flowers_plus/init.lua:74> In thread b693a220: /home/minetest/Server/src/main.cpp:1870: int main(int, char**): Assertion '0' failed. Debug stacks: DEBUG STACK FOR THREAD b20ff440: #0 virtual void* CurlFetchThread::Thread() DEBUG STACK FOR THREAD b693a220: #0 int main(int, char**) (Leftover data: #1 Dedicated server branch) (Leftover data: #2 virtual void ServerMap::save(ModifiedState)) (Leftover data: #3 virtual void Database_SQLite3::saveBlock(MapBlock*)) (Leftover data: #4 void ItemStack::serialize(std::ostream&) const) Aborted ``` I did not test that yet, will comment again here when tested. --- api.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/api.lua b/api.lua index d6a2cfd..4458ba4 100644 --- a/api.lua +++ b/api.lua @@ -2,13 +2,15 @@ -- Returns a list of areas that include the provided position function areas:getAreasAtPos(pos) local a = {} - local px, py, pz = pos.x, pos.y, pos.z - for id, area in pairs(self.areas) do - local ap1, ap2 = area.pos1, area.pos2 - if px >= ap1.x and px <= ap2.x and - py >= ap1.y and py <= ap2.y and - pz >= ap1.z and pz <= ap2.z then - a[id] = area + if pos then + local px, py, pz = pos.x, pos.y, pos.z + for id, area in pairs(self.areas) do + local ap1, ap2 = area.pos1, area.pos2 + if px >= ap1.x and px <= ap2.x and + py >= ap1.y and py <= ap2.y and + pz >= ap1.z and pz <= ap2.z then + a[id] = area + end end end return a