Skip to content

Swapping items in inventory while a "Use" action is pending can cause TypeError #137

@Cyborger1

Description

@Cyborger1

If you select an item to "Use" in your inventory, then swap items around, the indicator for the pending item to be used is not swapped/updated accordingly.

Knowing this, it's possible to swap the item out of the slot, leaving it empty. This causes the game to freak out because it's trying to render the possible action of using an item from an empty slot.

Use an item:
image

Move it out of the slot:
image

Game window freezes, this gets spammed in the dev console every frame:

Uncaught TypeError: Cannot read properties of undefined (reading 'item')
    at Inventory.selectedName (ui_inventory.js:6:142)
    at updateMouseSelectForInventory (items.js:85:272)
    at updateContextOptions (mouse.js:34:145)
    at animate (client.js:11:371)

Quick fix, add a guard clause to prevent the game window from freezing.

selectedName() {
    if (this.selected === undefined)
        return;
    let item_stack = this.items[this.selected];
    if (item_stack === undefined)
        return;
    return "<span class='item'>" + itemName(item_stack.item) + "</span>";
}

Ideally however, swapping around items in the inventory should clear the selected item, or clear the selection if the slot ever becomes empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    client-bugAn issue with the Genfanad client.fix-pending-releaseThis has been confirmed by the team and a fix will be released soon.team-confirmedThis has been confirmed by a member of the Genfanad team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions