Skip to content

Update hooks.lua to fix crash when leaving lobby - #149

Open
Xzyer wants to merge 1 commit into
lord-ruby:mainfrom
Xzyer:Xzyer-patch-1
Open

Update hooks.lua to fix crash when leaving lobby#149
Xzyer wants to merge 1 commit into
lord-ruby:mainfrom
Xzyer:Xzyer-patch-1

Conversation

@Xzyer

@Xzyer Xzyer commented Aug 14, 2026

Copy link
Copy Markdown

When a player leaves a multiplayer lobby (or an opponent disconnects), Entropy crashes with:

[SMODS entr "lib/hooks.lua"]:1169: bad argument #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:

 for i, a in pairs(SMODS.get_card_areas('jokers')) do
        for _, c in pairs(a.cards) do

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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant