Skip to content

NullReferenceException in AdjustBaseUnenchanted when playing an enchanted Shiv #365

Description

@54muzi

Environment

  • BaseLib: 3.4.0
  • Slay the Spire 2: v0.110.0
  • Platform: Windows / Steam

Reproduction

  1. Play as the Hunter.
  2. Play BLADE_OF_INK.
  3. Obtain the enchanted SHIV created by the card.
  4. Play that Shiv.

Actual behavior

The card resolution throws a NullReferenceException. The combat turn loop then
dies and the combat remains stuck until the room is restarted.

Relevant stack frame:

System.NullReferenceException
at BaseLib.Patches.Hooks.ModifyBaseDamagePatches.AdjustBaseUnenchanted(
    Boolean runGlobalHooks,
    Decimal num,
    DynamicVar dynVar,
    CardModel card)

Root cause

CardOwnerForVar(DynamicVar dynVar) returns CardModel?, but its result is
passed to AdjustBaseUnenchanted, whose first statement dereferences
card.Enchantment without checking whether card is null.

The analogous AdjustExtraUnenchanted method already accepts CardModel? and
handles this case.

Suggested fix

static decimal AdjustBaseUnenchanted(
    bool runGlobalHooks,
    decimal num,
    DynamicVar dynVar,
    CardModel? card)
{
    if (card == null || card.Enchantment != null) return num;
    // existing logic...
}

I tested the equivalent null guard as a local binary hotfix. BaseLib initialized
with 272 patches successfully, 0 failed, and the previously freezing
Blade of Ink 鈫?enchanted Shiv interaction completed normally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions