Infixo / Civ6-Real-Strategy

Civ6 Real Strategy mod
8 stars 1 forks source link

Nil value in RefreshNavalData #15

Closed Infixo closed 1 year ago

Infixo commented 1 year ago

[from Steam workshop] Frinckles 23 May, 2021 @ 10:00pm  Awesome mod. Needs to be fixed for MP and possibly single player. The cause for de-syncs seems to have something to do with naval travel. In SP I'll get a CTD while navigating the world or when the game wants me to do something with a Galley. Runtime Error: Lua\RealStrategy.lua:1919: attempt to index a nil value stack traceback: \Lua\RealStrategy.lua:1919: in function 'RefreshNavalData' \Lua\RealStrategy.lua:1945: in function 'ActiveStrategyNaval' Lua callstack: PlotInfo: PlotInfo::OnCitySelectionChanged 0 131073 0 0 0 false false PlotInfo: PlotInfo::OnCitySelectionChanged 0 131073 16 13 0 true false PlotInfo: PlotInfo::OnCitySelectionChanged 0 131073 0 0 0 false false PlotInfo: PlotInfo::OnCitySelectionChanged 0 196610 17 18 0 true false The de-syncs may have something to do with the AI getting what a human player would normally perceive as a CTD by moving ships. Could test by disabling that module or playing a map with no water .Anyway, thanks for your hard work on the mod.

=== @frinckles TYVM. You are the first to actually provide a useful info. I looked into this error from line 1919 and it seems that RST is trying to read data for a non-existent player, probably killed. I will look into this more soon. Could be an easy fix.

=== ChrisMartin 17 Jul, 2021 @ 10:34pm  I get this in my Lua.log several times: Lua callstack: Runtime Error: D:\Steam\steamapps\workshop\content\289070\1617282434\Lua\RealStrategy.lua:1919: attempt to index a nil value stack traceback: D:\Steam\steamapps\workshop\content\289070\1617282434\Lua\RealStrategy.lua:1919: in function 'RefreshNavalData' D:\Steam\steamapps\workshop\content\289070\1617282434\Lua\RealStrategy.lua:1945: in function 'ActiveStrategyNaval' Could it be some hick-ups with Barb-Mode?

=== ts227 [has Sid Meier's Civilization VI] 1 Jan, 2022 @ 9:51pm  @infixio Game crashed when leaving a match. The log suggests it's a bug in this mod: RealStrategy.lua:1919: attempt to index a nil value RealStrategy.lua:1919: in function RefreshNavalData RealStrategy.lua:1945: in function ActiveStrategyNaval This was in a match with AutoPlay, but it seems to happen in normal matches as well.

Infixo commented 1 year ago

SOLUTION @Plaidygami

Try adding one line in this function.

function RefreshNavalData(ePlayerID:number) --print(Game.GetCurrentGameTurn(), "FUN RefreshNavalData", ePlayerID);

-- check if data needs to be refreshed local data:table = tData[ePlayerID]; if data.TurnRefreshNaval == Game.GetCurrentGameTurn() then return; end -- we already refreshed on this turn

after line 1918: local data:table = tData[ePlayerID];

add this: if data == nil or data.Data == nil then return false; end

The error is usually caused by a killed civ. The mod still tried to analyze it and I made some safechecks, but I could've missed one.