Gregory365 / TPF2-Timetables

The Timetable mod for Transport Fever 2
GNU General Public License v3.0
13 stars 5 forks source link

Random Error in timetable GUI - clearConstraintWindowLaterHACK #40

Closed Gregory365 closed 1 year ago

Gregory365 commented 1 year ago

Error message: error: [string "D:/SteamLibrary/steamapps/workshop/content/1066780/2918585390/res/config/game_script/timetable_gui.lua"]:838: bad argument #1 to 'pairs' (table expected, got number) stack traceback: =C: ? =C: pairs D:/SteamLibrary/steamapps/workshop/content/1066780/2918585390/res/config/game_script/timetable_gui.lua(838): makeArrDepWindow D:/SteamLibrary/steamapps/workshop/content/1066780/2918585390/res/config/game_script/timetable_gui.lua(804): clearConstraintWindowLaterHACK D:/SteamLibrary/steamapps/workshop/content/1066780/2918585390/res/config/game_script/timetable_gui.lua(1170): ?

Caused by timetable.getCondition() returning a -1 error code instead of a table, and then timetable_gui attempts to unwrap using the lua pairs() function but fails as pairs requires table as a parameter, not a number

The cause us likely due to a line or station being deleted at the same time as the timetable window is opened, or another similarly rare event.

The fix for this issue is to ensure that errors are handled gracefully throughout timetable_gui. Also note that clearConstraintWindowLaterHACK was the calling function to this, and should probably be replaced somehow as it is likely the lineID and stationID became invalid during the gap between the function being defined and being called.

[Don't try to reproduce, you won't be able to]

Gregory365 commented 1 year ago

Need to remove clearConstraintWindowLaterHACK. Need to get elements to not destroy themselves while handling a click event, so this requires a refactor.

Gregory365 commented 1 year ago

Related to #8

Gregory365 commented 1 year ago

Fixed in #54