Page 1 of 1

Bug in game_deployment.lua

Posted: Sat May 25, 2013 8:38 am
by KeldorKatarn
Recently my game crashed with the following message: Attempt to index a nil value.

The error occured in line 447 which is the first line of this function's body.

function ApplySlotState(unit, slot)
unit.luaData.quality = unit.faction.luaData.slots[slot].quality
unit.efficiency = unit.luaData.quality
UpdateUnit(unit, unit.faction.luaData.slots[slot].techs)

ClearSlot(unit.faction, slot)
end

apparently unit.faction.luaData.slots[slot] is nil.

I could fix my savegame by changing the function like this:

function ApplySlotState(unit, slot)
if unit.faction.luaData.slots[slot] ~= nil then
unit.luaData.quality = unit.faction.luaData.slots[slot].quality
unit.efficiency = unit.luaData.quality
UpdateUnit(unit, unit.faction.luaData.slots[slot].techs)

ClearSlot(unit.faction, slot)
end
end

Savegame to reproduce reliably attached.

Please comment whether this fix is correct to I can apply the correct fix manually until the next patch arrives.

Re: Bug in game_deployment.lua

Posted: Sun May 26, 2013 11:08 am
by lordzimoa
I have Szymon have a look tomorrow morning when he is back in office, thanks for the report!

Re: Bug in game_deployment.lua

Posted: Sun May 26, 2013 11:12 am
by KeldorKatarn
Well what a gamers that are also fellow developers (and can read LUA) for ;-) The nil check is probably just a work around. The real issue seems to be that the function is called when the value can be nil. (Unless that's completely alright, then the nil check is just missing). Anyway, should be an easy fix with the savegame.