Jump to content

Missed nil check in maprevealable.lua


clearlove
  • Fixed

In the function `MapRevealable:Refresh()`, I think it will be better if you add a nil check of the `v.components.maprevealer` before calling `v.components.maprevealer:GetPrivateOwner()`.

local MAPREVEALER_TAGS = {"maprevealer"}
function MapRevealable:Refresh()
    if self.task ~= nil then
		local newps, ispublic
		local x, y, z = self.inst.Transform:GetWorldPosition()
		for _, v in ipairs(TheSim:FindEntities(x, y, z, PLAYER_REVEAL_RADIUS, nil, nil, MAPREVEALER_TAGS)) do
			if v ~= self.inst then
				-- ******************** NEED NIL CHECK HERE **********************
				local privateowner = v.components.maprevealer:GetPrivateOwner()
				if privateowner then
					if privateowner.isplayer and privateowner ~= self.inst and privateowner ~= v and privateowner:IsValid() then
						newps = newps or {}
						newps[privateowner] = true
					end
				else
					ispublic = true
					for k in pairs(self.privatesources) do
						self:RemovePrivateSource(k)
					end
					self:AddRevealSource("maprevealer")
					break
				end
			end
		end
		if not ispublic then
            self:RemoveRevealSource("maprevealer")
			if newps then
				for k in pairs(self.privatesources) do
					if newps[k] then
						newps[k] = nil
					else
						self:RemovePrivateSource(k)
					end
				end
				for k in pairs(newps) do
					self:AddPrivateSource(k)
				end
			else
				for k in pairs(self.privatesources) do
					self:RemovePrivateSource(k)
				end
            end
        end
    end
    if self.onrefreshfn ~= nil then
        self.onrefreshfn(self.inst)
    end
end

The function is in maprevealable.lua line 196. This does not make the game crash, but makes some mods unstable. 


Steps to Reproduce

Just read the codes above.




User Feedback


A developer has marked this issue as fixed. This means that the issue has been addressed in the current development build and will likely be in the next update.


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
  • Create New...