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.
This commit is contained in:
Megaf 2014-06-22 20:42:26 -03:00
parent bfb260d181
commit c876179024
1 changed files with 9 additions and 7 deletions

16
api.lua
View File

@ -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