zenyr/PocoHud3

"mods/PocoHud3/poco/../poco/Hud3.lua:1280: attempt to index a nil value" crash

Opened this issue · 2 comments

I'm getting a "mods/PocoHud3/poco/../poco/Hud3.lua:1280: attempt to index a nil value" crash as of the current version. This is on line unit = managers.network:session():peer(something):unit() in function TPocoHud3:_pos(something,head).

This crash happened shortly (about a second) after one of the players I was in the lobby in has disconnected from the game.

zenyr commented

Thanks for the report.

But it is hard to pinpoint the crash just yet. How often does it happen? As long as someone let me reproduce the crash I can fix it.

Usually I end up putting safety check(cheap if-check or pricey _.g() fetcher) beforehand but this one is called quite frequently so I should be a bit more precise here.

Anyone with more info are welcomed. I also play-test my mod myself (note that I rarely mix mods) so I'll fix this as soon as I have this problem.

Thanks again and this issue is left open.

I estimate it to be around a 20% chance of crashing if someone disconnects. I've modified the code to call the crashing function through pcall:

local function TPocoHud3__pos_crashfix(something) 
	return managers.network:session():peer(something):unit()
end 

local status, ret = pcall(TPocoHud3__pos_crashfix, something) 
if status == true then 
	unit = ret
else 
	log("PocoHud TPocoHud3:_pos error: " .. tostring(ret))
	return Vector3()
end

It's probably not optimal (although I don't notice any performance issues), but it prevents the crash and just outputs the error in the BLT console and log (which also says that the error happens after someone disconnects). Sample BLT console log (with the above pcall):

02:28:00 PM Lua: [1] SYSTEM: (username here) disconnected.
02:28:00 PM FATAL ERROR: mods/PocoHud3/poco/../poco/Hud3.lua:1279: attempt to index a nil value
02:28:00 PM Lua: PocoHud TPocoHud3:_pos error: nil

If anyone knows of an 'if then' workaround or anything more optimal, that would help a lot.