jopeek / fvtt-loot-sheet-npc-5e

FVTT - Loot Sheet NPC 5E
MIT License
44 stars 86 forks source link

Unable to open loot sheet when "gp"=null, with stack trace #375

Closed Majea closed 1 week ago

Majea commented 2 years ago

Describe the bug We using chests actors for the players to store the items they don't want to carry around. Those actors are setup as loot sheets. It seems that one of the players has stored an item or edited the amount of gold pieces in such a way that the "gp" property becomes null. This makes the loot sheet plugin crash and the actor sheet doesn't open anymore.

To Reproduce

  1. open an actor setup with the loot sheet npc 5e sheet type
  2. go to the second tab (inventory) where the currencies are displayed
  3. delete the value for the number of gold pieces (gp). Do not set the value to 0. Keep the field blank
  4. leave the field and close the sheet
  5. At this point, the number of gp is null and the actor sheet can't be opened anymore

Here is the actor for which the sheet doesn't open anymore: {"_id":"VOGsbdTxaidpgMat","name":"Coffre de Garedus","type":"npc","img":"icons/containers/chest/chest-reinforced-steel-red.webp","data":{"abilities":{"str":{"value":10,"proficient":0,"bonuses":{"check":"","save":""},"mod":0,"checkProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"saveBonus":0,"saveProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"checkBonus":0,"save":0,"dc":10},"dex":{"value":10,"proficient":0,"bonuses":{"check":"","save":""},"mod":0,"checkProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"saveBonus":0,"saveProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"checkBonus":0,"save":0,"dc":10},"con":{"value":10,"proficient":0,"bonuses":{"check":"","save":""},"mod":0,"checkProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"saveBonus":0,"saveProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"checkBonus":0,"save":0,"dc":10},"int":{"value":10,"proficient":0,"bonuses":{"check":"","save":""},"mod":0,"checkProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"saveBonus":0,"saveProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"checkBonus":0,"save":0,"dc":10},"wis":{"value":10,"proficient":0,"bonuses":{"check":"","save":""},"mod":0,"checkProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"saveBonus":0,"saveProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"checkBonus":0,"save":0,"dc":10},"cha":{"value":10,"proficient":0,"bonuses":{"check":"","save":""},"mod":0,"checkProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"saveBonus":0,"saveProf":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"checkBonus":0,"save":0,"dc":10}},"attributes":{"ac":{"flat":10,"calc":"natural","formula":"","base":10,"cover":0,"bonus":0,"shield":0,"warnings":[],"dex":0},"hp":{"value":10,"min":0,"max":10,"temp":null,"tempmax":0,"formula":""},"init":{"value":0,"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"total":0},"movement":{"burrow":0,"climb":0,"fly":0,"swim":0,"walk":9,"units":"m","hover":false},"attunement":{"max":3},"senses":{"darkvision":0,"blindsight":0,"tremorsense":0,"truesight":0,"units":"ft","special":""},"spellcasting":"int","prof":2,"encumbrance":{"value":0,"max":68,"pct":0,"encumbered":false},"spelldc":10},"details":{"biography":{"value":"","public":""},"alignment":"","race":"","type":{"value":"","subtype":"","swarm":"","custom":""},"environment":"","cr":1,"spellLevel":0,"xp":{"value":200},"source":""},"traits":{"size":"med","di":{"value":[],"custom":""},"dr":{"value":[],"custom":""},"dv":{"value":[],"custom":""},"ci":{"value":[],"custom":""},"languages":{"value":[],"custom":""}},"currency":{"pp":0,"gp":null,"ep":0,"sp":0,"cp":0},"skills":{"acr":{"value":0,"ability":"dex","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"ani":{"value":0,"ability":"wis","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"arc":{"value":0,"ability":"int","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"ath":{"value":0,"ability":"str","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"dec":{"value":0,"ability":"cha","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"his":{"value":0,"ability":"int","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"ins":{"value":0,"ability":"wis","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"itm":{"value":0,"ability":"cha","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"inv":{"value":0,"ability":"int","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"med":{"value":0,"ability":"wis","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"nat":{"value":0,"ability":"int","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"prc":{"value":0,"ability":"wis","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"prf":{"value":0,"ability":"cha","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"per":{"value":0,"ability":"cha","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"rel":{"value":0,"ability":"int","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"slt":{"value":0,"ability":"dex","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"ste":{"value":0,"ability":"dex","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10},"sur":{"value":0,"ability":"wis","bonuses":{"check":"","passive":""},"bonus":0,"mod":0,"prof":{"_baseProficiency":2,"multiplier":0,"rounding":"down"},"proficient":0,"total":0,"passive":10}},"spells":{"spell1":{"value":0,"override":null,"max":0},"spell2":{"value":0,"override":null,"max":0},"spell3":{"value":0,"override":null,"max":0},"spell4":{"value":0,"override":null,"max":0},"spell5":{"value":0,"override":null,"max":0},"spell6":{"value":0,"override":null,"max":0},"spell7":{"value":0,"override":null,"max":0},"spell8":{"value":0,"override":null,"max":0},"spell9":{"value":0,"override":null,"max":0},"pact":{"value":0,"override":null,"max":0,"level":0}},"bonuses":{"mwak":{"attack":"","damage":""},"rwak":{"attack":"","damage":""},"msak":{"attack":"","damage":""},"rsak":{"attack":"","damage":""},"abilities":{"check":"","save":"","skill":""},"spell":{"dc":""}},"resources":{"legact":{"value":0,"max":0},"legres":{"value":0,"max":0},"lair":{"value":false,"initiative":0}},"prof":{"_baseProficiency":2,"multiplier":1,"rounding":"down"},"classes":{},"flags":{"lootsheetnpc5e":{"lootsheettype":"Loot","rolltable":"","shopQty":"","itemQty":"","itemQtyLimit":"","clearInventory":false,"currencyFormula":"","permissionsFilter":"2","darkMode":false,"sheettint":{"value":"#000000","alpha":0.5,"style":"","blendmode":"difference"},"avatartint":{"value":"#000000","alpha":0.5}}}},"token":{"name":"Coffre de Garedus","img":"moulinette/images/custom/majea/furniture/chest7.png","displayName":0,"actorLink":true,"width":1,"height":1,"scale":1,"mirrorX":false,"mirrorY":false,"lockRotation":false,"rotation":0,"alpha":1,"vision":false,"dimSight":0,"brightSight":0,"sightAngle":0,"light":{"alpha":0.5,"angle":0,"bright":0,"coloration":1,"dim":0,"gradual":true,"luminosity":0.5,"saturation":0,"contrast":0,"shadows":0,"animation":{"speed":5,"intensity":5,"reverse":false},"darkness":{"min":0,"max":1},"color":null},"disposition":-1,"displayBars":0,"bar1":{"attribute":"attributes.hp"},"bar2":{"attribute":""},"flags":{},"randomImg":false,"tint":null,"x":null,"y":null,"elevation":null},"items":[],"effects":[],"folder":"7dlFCL6PNYhMjzm3","sort":0,"permission":{"default":0,"we2DLbDtNWPsVQg5":3,"lI7Ae408bhqbK49G":0,"kZtsV0Q60qrMcHmS":0,"alshaIPDgLuWlH4s":0,"KIzDEck9o5aSHjCD":0,"rw82CDlvBrVz0g3j":3,"nlIpdF2unl8RgIWk":0,"i8f1M20q0wNJKdbE":0,"mZszw08JBCscZgX2":0},"flags":{"core":{"sheetClass":"dnd5e.LootSheetNPC5e"},"lootsheetnpc5e":{"lootsheettype":"Loot","permissionsFilter":"false","rolltable":"","shopQty":"","itemQty":"","itemQtyLimit":"","currencyFormula":"","clearInventory":false,"darkMode":false,"sheettint":{"value":"#000000","alpha":0.5,"style":"none","blendmode":"difference"},"avatartint":{"value":"#000000","alpha":0.5}}}} The issue is in this piece of the data structure:

"currency": {
    "pp": 0,
    "gp": null,
    "ep": 0,
    "sp": 0,
    "cp": 0
},

Replacing "gp": null by "gp": 0 manually in the database fixes the issue.

The first time I try to open the sheet, I have the following stack trace:

foundry.js:319 TypeError: Cannot read properties of null (reading 'toString')
[Detected 1 package: lootsheetnpc5e]
    at Object.<anonymous> (HandlebarsHelper.js:92)
    at Object.c (handlebars.min.js:27)
    at eval (eval at createFunctionContext (handlebars.min.js:29), <anonymous>:17:163)
    at h (handlebars.min.js:27)
    at c (handlebars.min.js:27)
    at handlebars.min.js:27
    at Array.forEach (<anonymous>)
    at handlebars.min.js:27
    at Object.<anonymous> (handlebars.min.js:27)
    at Object.c (handlebars.min.js:27)
    at Object.eval [as main] (eval at createFunctionContext (handlebars.min.js:29), <anonymous>:11:49)
    at c (handlebars.min.js:27)
    at d (handlebars.min.js:27)
    at e (handlebars.min.js:28)
    at Object.h (handlebars.min.js:27)
    at Object.c [as invokePartial] (handlebars.min.js:27)
    at Object.eval [as main] (eval at createFunctionContext (handlebars.min.js:29), <anonymous>:17:28)
    at c (handlebars.min.js:27)
    at d (handlebars.min.js:27)
    at e (handlebars.min.js:28)
    at Object.h (handlebars.min.js:27)
    at Object.c [as invokePartial] (handlebars.min.js:27)
    at Object.eval [as main] (eval at createFunctionContext (handlebars.min.js:29), <anonymous>:15:28)
    at c (handlebars.min.js:27)
    at d (handlebars.min.js:27)
    at e (handlebars.min.js:28)
    at Object.h (handlebars.min.js:27)
    at Object.c [as invokePartial] (handlebars.min.js:27)
    at Object.eval [as main] (eval at createFunctionContext (handlebars.min.js:29), <anonymous>:25:28)
    at c (handlebars.min.js:27)
    at d (handlebars.min.js:27)
    at e (handlebars.min.js:28)
    at renderTemplate (foundry.js:4696)
    at async LootSheetNPC5e._renderInner (foundry.js:3235)
    at async LootSheetNPC5e._renderInner (foundry.js:3775)
    at async LootSheetNPC5e._render (foundry.js:3068)
    at async LootSheetNPC5e._render (foundry.js:3764)

After that, all the other attempts give that other stack trace:

Foundry VTT | Rendering LootSheetNPC5e
foundry.js:319 Error: One of original or other are not Objects!
[Detected 1 package: lootsheetnpc5e]
    at mergeObject (helpers.mjs:472)
    at _mergeUpdate (helpers.mjs:527)
    at mergeObject (helpers.mjs:486)
    at _mergeUpdate (helpers.mjs:527)
    at mergeObject (helpers.mjs:486)
    at _mergeUpdate (helpers.mjs:527)
    at Module.mergeObject (helpers.mjs:486)
    at LootSheetNPC5e._render (foundry.js:3058)
    at LootSheetNPC5e._render (foundry.js:3764)
    at LootSheetNPC5e.render (foundry.js:3021)
    at LootSheetNPC5e.render (foundry.js:4259)
    at LootSheetNPC5e.render (LootsheetNPC5e.js:139)
    at Token5e._onClickLeft2 (foundry.js:39056)
    at MouseInteractionManager.callback (foundry.js:24247)
    at MouseInteractionManager._handleClickLeft2 (foundry.js:24451)
    at MouseInteractionManager._handleMouseDown (foundry.js:24413)
    at Token5e.a.emit (index.js:181)
    at r.dispatchEvent (interaction.min.js:8)
    at r.processPointerDown (interaction.min.js:8)
    at t.recursiveFindHit (interaction.min.js:8)
    at t.recursiveFindHit (interaction.min.js:8)
    at t.recursiveFindHit (interaction.min.js:8)
    at t.recursiveFindHit (interaction.min.js:8)
    at t.recursiveFindHit (interaction.min.js:8)
    at t.findHit (interaction.min.js:8)
    at r.processInteractive (interaction.min.js:8)
    at r.onPointerDown (interaction.min.js:8)
onError @ foundry.js:319
🎁call_wrapped @ libWrapper-wrapper.js:511
🎁Hooks.onError#lib-wrapper @ listeners.js:137
🎁Hooks.onError#0 @ libWrapper-wrapper.js:187
(anonymous) @ foundry.js:3023
Promise.catch (async)
render @ foundry.js:3021
render @ foundry.js:4259
render @ LootsheetNPC5e.js:139
_onClickLeft2 @ foundry.js:39056
callback @ foundry.js:24247
_handleClickLeft2 @ foundry.js:24451
_handleMouseDown @ foundry.js:24413
a.emit @ index.js:181
r.dispatchEvent @ interaction.min.js:8
r.processPointerDown @ interaction.min.js:8
t.recursiveFindHit @ interaction.min.js:8
t.recursiveFindHit @ interaction.min.js:8
t.recursiveFindHit @ interaction.min.js:8
t.recursiveFindHit @ interaction.min.js:8
t.recursiveFindHit @ interaction.min.js:8
t.findHit @ interaction.min.js:8
r.processInteractive @ interaction.min.js:8
r.onPointerDown @ interaction.min.js:8

Expected behavior I would expect the sheet to open. The code should either consider null values as 0 or replace any null value by a 0.

Desktop (please complete the following information):

Majea commented 2 years ago

Side note: the same problem most likely happens with the other currencies as well, tough I didn't check that myself.