Nexela / PickerInventoryTools

Other
1 stars 4 forks source link

Fix NRE in update_item_count_settings() #18

Closed DeviousNull closed 6 months ago

DeviousNull commented 1 year ago

The 'on_runtime_mod_setting_changed' event may include a nil value for 'event.player_index', which can result in a non-recoverable error when starting a new game.

I specifically observed this issue with the Project Cybersyn mod (version 1.2.13) installed.

PIT-Error

The following series of events occurs:

  1. A new game is started.
  2. Cybersyn changes one of its own settings in its 'on_init' function.
  3. An 'on_runtime_mod_setting_changed' event is dispatched (with a nil player_index).
  4. The 'update_item_count_settings' function runs, and attempts to index an array with the nil player_index; this raises an Exception.
  5. Stdlib re-raises the Exception as a non-recoverable error, since no player has been added to the game yet.

By moving the array index statement into the existing if-statement's scope, we can ensure that player_index is not nil (since Picker Inventory Tools is the only mod that should modify the 'picker-item-count' setting).