From cab9ff9546337f8b531f95245ecb476b1329e063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Tue, 30 Sep 2025 17:41:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(Feed):=20=E6=B7=BB=E5=8A=A0UIState.player?= =?UTF-8?q?=E6=9C=89=E6=95=88=E6=80=A7=E6=A3=80=E6=9F=A5=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在rebuildInfo方法中增加对UIState.player的实例有效性检查,防止当player为null时导致的空指针异常。同时确保weaponShow.operation和costShow.enough的正确设置。 --- scripts/Structs/Feed.gd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/Structs/Feed.gd b/scripts/Structs/Feed.gd index f8493af..eccd24f 100644 --- a/scripts/Structs/Feed.gd +++ b/scripts/Structs/Feed.gd @@ -96,7 +96,8 @@ func rebuildInfo(): for weapon in weapons: var weaponShow: WeaponShow = ComponentManager.getUIComponent("WeaponShow").instantiate() weaponShow.weapon = weapon - weaponShow.operation = WeaponShow.Operation.EXTRACT if UIState.player.weaponBag.has(weapon.instantiate().displayName) else WeaponShow.Operation.GET + if is_instance_valid(UIState.player): + weaponShow.operation = WeaponShow.Operation.EXTRACT if UIState.player.weaponBag.has(weapon.instantiate().displayName) else WeaponShow.Operation.GET weaponShow.visible = true weaponsBox.add_child(weaponShow) for i in costsBox.get_children(): @@ -105,7 +106,7 @@ func rebuildInfo(): var cost = costs[i] var count = countOf(i) var costShow: ItemShow = ComponentManager.getUIComponent("ItemShow").instantiate() - costShow.enough = UIState.player.inventory[cost] >= count + costShow.enough = is_instance_valid(UIState.player) and UIState.player.inventory[cost] >= count costShow.type = cost costShow.count = count costsBox.add_child(costShow)