Update hooks.lua to fix crash when leaving lobby - #149
Open
Xzyer wants to merge 1 commit into
Open
Conversation
When a player leaves a multiplayer lobby (or an opponent disconnects), Entropy crashes with: [SMODS entr "lib/hooks.lua"]:1169: bad argument lord-ruby#1 to 'pairs' (table expected, got nil) The crash occurs during the transition from the multiplayer lobby state back to the main menu. SMODS.get_card_areas('jokers') returns a non-nil table of area objects, but those area objects have a nil .cards field because the jokers area has not been fully initialized yet during this game-state transition. Affected locations in lib/hooks.lua: - Line ~1169 — inside create_card function (the primary crash site) - Line ~2170 — inside add_tag function - Line ~3138 — inside interest calculation function All three iterate over _joker_areas = SMODS.get_card_areas('jokers') and then call pairs(a.cards) without checking if .cards is nil. Reproduction: 1. Join a multiplayer game lobby with Entropy installed 2. Leave the lobby (or have an opponent disconnect) 3. Game crashes on transition back to main menu Proposed fix: Add nil guards around a.cards in all three locations: Before: local _joker_areas = SMODS.get_card_areas('jokers') if _joker_areas then for i, a in pairs(_joker_areas) do for _, c in pairs(a.cards) do -- crashes if a.cards is nil After: local _joker_areas = SMODS.get_card_areas('jokers') if _joker_areas then for i, a in pairs(_joker_areas) do if a.cards then <-- guard added for _, c in pairs(a.cards) do This is safe because skipping the loop when .cards is nil has no functional impact — there are simply no jokers to process during this state transition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a player leaves a multiplayer lobby (or an opponent disconnects), Entropy crashes with:
The crash occurs during the transition from the multiplayer lobby state back to the main menu. SMODS.get_card_areas('jokers') returns a non-nil table of area objects, but those area objects have a nil .cards field because the jokers area has not been fully initialized yet during this game-state transition.
Affected locations in lib/hooks.lua:
- Line ~1169 — inside create_card function (the primary crash site)
- Line ~2170 — inside add_tag function
- Line ~3138 — inside interest calculation function
All three iterate over _joker_areas = SMODS.get_card_areas('jokers') and then call pairs(a.cards) without checking if .cards is nil.
Reproduction:
1. Join a multiplayer game lobby with Entropy installed
2. Leave the lobby (or have an opponent disconnect)
3. Game crashes on transition back to main menu
Proposed fix: Add nil guards around a.cards in all three locations:
Before:
After: