From 98de7323aa926310741aee1fdc553abadd38ca9c Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Wed, 11 Sep 2024 01:31:22 -0400 Subject: [PATCH 1/3] fix crash in hud_get_custom_gauge() The `Player_ship` variable can sometimes be NULL, especially in FRED, so revise the conditional to check for this. --- code/hud/hud.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/hud/hud.cpp b/code/hud/hud.cpp index 46a913b1598..20b7640df5b 100644 --- a/code/hud/hud.cpp +++ b/code/hud/hud.cpp @@ -3908,7 +3908,9 @@ void hud_page_in() HudGauge* hud_get_custom_gauge(const char* name, bool check_all_gauges) { - auto player_sip = Player_ship->ship_info_index < 0 ? nullptr : &Ship_info[Player_ship->ship_info_index]; + ship_info *player_sip = nullptr; + if (Player_ship && Player_ship->ship_info_index >= 0) + player_sip = &Ship_info[Player_ship->ship_info_index]; // go through all gauges for all ships and defaults if (check_all_gauges) { From 2f3423d70ebb4f0f248cd6f9f93a23dcde1deb0b Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Wed, 11 Sep 2024 01:45:44 -0400 Subject: [PATCH 2/3] fix "hudgauge" custom parameter Since the `OPF_ANY_HUD_GAUGE` type checks for any default or custom HUD gauge in regular SEXP operators, it should do so in scripted SEXP operators as well. --- code/parse/sexp/LuaSEXP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/parse/sexp/LuaSEXP.cpp b/code/parse/sexp/LuaSEXP.cpp index b64dd246ff5..5630c81a7a1 100644 --- a/code/parse/sexp/LuaSEXP.cpp +++ b/code/parse/sexp/LuaSEXP.cpp @@ -302,7 +302,7 @@ luacpp::LuaValue LuaSEXP::sexpToLua(int node, int argnum, int parent_node) const } case OPF_ANY_HUD_GAUGE: { auto name = CTEXT(node); - return LuaValue::createValue(_action.getLuaState(), l_HudGauge.Set(hud_get_gauge(name))); + return LuaValue::createValue(_action.getLuaState(), l_HudGauge.Set(hud_get_gauge(name, true))); } case OPF_EVENT_NAME: { auto name = CTEXT(node); From dfe34ec58d93652e88d59d43f1a4ab291f963eb2 Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Wed, 11 Sep 2024 02:03:40 -0400 Subject: [PATCH 3/3] update documentation --- code/scripting/api/objs/hudgauge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/scripting/api/objs/hudgauge.cpp b/code/scripting/api/objs/hudgauge.cpp index 115bba6e10f..e02054c6a71 100644 --- a/code/scripting/api/objs/hudgauge.cpp +++ b/code/scripting/api/objs/hudgauge.cpp @@ -21,7 +21,7 @@ ADE_FUNC(isCustom, l_HudGauge, nullptr, "Custom HUD Gauge status", "boolean", "R return ade_set_args(L, "b", gauge->isCustom()); } -ADE_VIRTVAR(Name, l_HudGauge, "string", "Custom HUD Gauge name", "string", "Custom HUD Gauge name, or blank if this is a default gauge, or nil if handle is invalid") +ADE_VIRTVAR(Name, l_HudGauge, "string", "Custom HUD Gauge name", "string", "Custom HUD Gauge name, or nil if this is a default gauge or the handle is invalid") { HudGauge* gauge; @@ -37,7 +37,7 @@ ADE_VIRTVAR(Name, l_HudGauge, "string", "Custom HUD Gauge name", "string", "Cust return ade_set_args(L, "s", gauge->getCustomGaugeName()); } -ADE_VIRTVAR(Text, l_HudGauge, "string", "Custom HUD Gauge text", "string", "Custom HUD Gauge text, or blank if this is a default gauge, or nil if handle is invalid") +ADE_VIRTVAR(Text, l_HudGauge, "string", "Custom HUD Gauge text", "string", "Custom HUD Gauge text, or nil if this is a default gauge or the handle is invalid") { HudGauge* gauge; const char* text = nullptr;