Skip to content

Conversation

@In3luki
Copy link
Collaborator

@In3luki In3luki commented Nov 9, 2025

The handleHPChange function creates an actor clone on every physical item update even when the HP did not change. The observed error happens when the actor clone is created with an invalid item source as Actor#toObject still includes the source of invalid embedded documents. The function is called from _preUpdate so a thrown error prevents the update from going through.

@In3luki In3luki force-pushed the fix-physical-item-hp-change branch from 67c416b to 9e54d8e Compare November 9, 2025 00:45
try {
// Get a clone of the item, through an actor clone if owned
const actorSource = item.actor?.toObject();
const changedSource = item.clone(fu.deepClone(changed), { keepId: true }).toObject();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just this part

Copy link
Collaborator Author

@In3luki In3luki Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error happens on line 275 when the new actor is created from the actorSource that may contain invalid item data.
itemClone on 276 is then referencing actorClone and itemClone itself is referenced on line 287.
I could make actorClone an IIFE to make the block smaller:

    const actorClone = ((): ActorPF2e | null => {
        try {
            return actorSource ? new ActorProxyPF2e(actorSource) : null;
        } catch {}
        return null;
    })();

Edit: Done that.

@In3luki In3luki force-pushed the fix-physical-item-hp-change branch from 9e54d8e to f890f0f Compare November 9, 2025 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants