Skip to content

Commit ce08dcc

Browse files
committed
fix(lua.endpoint): add nil checks for race condition in next_round endpoint
The condition in next_round.lua was accessing G.blind_select_opts immediately when G.STATE became BLIND_SELECT, but the UI elements are created asynchronously via Events in update_blind_select(). This caused crashes when loading saves from SHOP state because G.blind_select_opts wasn't populated yet when the state changed. Now properly waits for each component to be initialized: - G.STATE to be BLIND_SELECT - G.blind_select_opts table to exist - The specific blind pane (small/big/boss) to exist - The select button UI element to exist
1 parent 4af3d39 commit ce08dcc

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

src/lua/endpoints/next_round.lua

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,28 @@ return {
3232
trigger = "condition",
3333
blocking = false,
3434
func = function()
35-
local blind_pane = G.blind_select_opts[string.lower(G.GAME.blind_on_deck)]
35+
-- Wait for state transition and UI to be fully initialized
36+
if G.STATE ~= G.STATES.BLIND_SELECT then
37+
return false
38+
end
39+
if not G.blind_select_opts then
40+
return false
41+
end
42+
43+
local blind_key = string.lower(G.GAME.blind_on_deck)
44+
local blind_pane = G.blind_select_opts[blind_key]
45+
if not blind_pane then
46+
return false
47+
end
48+
3649
local select_button = blind_pane:get_UIE_by_ID("select_blind_button")
37-
local done = G.STATE == G.STATES.BLIND_SELECT and select_button ~= nil
38-
if done then
39-
sendDebugMessage("Return next_round() - reached BLIND_SELECT state", "BB.ENDPOINTS")
40-
send_response(BB_GAMESTATE.get_gamestate())
50+
if not select_button then
51+
return false
4152
end
42-
return done
53+
54+
sendDebugMessage("Return next_round() - reached BLIND_SELECT state", "BB.ENDPOINTS")
55+
send_response(BB_GAMESTATE.get_gamestate())
56+
return true
4357
end,
4458
}))
4559
end,

0 commit comments

Comments
 (0)