SchematicWebViewer icon indicating copy to clipboard operation
SchematicWebViewer copied to clipboard

Invalid tag value

Open IndexOutOfMJ opened this issue 1 year ago • 13 comments

Hey,

I tried to load a .schem file and a .nbt file and ran in both cases in this issue:

Error: Invalid tag value at getTagType (nbt.js:15:9) at nbt.js:30:12 at Array.forEach () at tagToRecord (nbt.js:28:20) at loadVersion2 (version2.js:49:5) at loadSchematic (loader.js:45:15) at renderer.js:113:13 at Generator.next () at renderer.js:44:66 at new ZoneAwarePromise (zone.js:2702:25)

This is the configuration i used:

renderSchematic(document.querySelector('#schematicRenderer'), base64, {
        size: {
          width: 889,
          height: 500
        },
        corsBypassUrl: 'https://corsproxy.io/'
      });

IndexOutOfMJ avatar Jul 23 '24 18:07 IndexOutOfMJ

Can you provide the files you tested?

octylFractal avatar Jul 23 '24 18:07 octylFractal

Sure

https://downloads.thenewempire.net/schematics/FINISHED_Medieval-Medium-Bridge_1.21.schem

IndexOutOfMJ avatar Jul 23 '24 19:07 IndexOutOfMJ

That is a valid schematic, so no issues there. How are you getting the base64 value?

octylFractal avatar Jul 23 '24 20:07 octylFractal

With this function:

async getData(reader: FileReader, file: Blob): Promise<string | null> { return new Promise((resolve) => { reader.onloadend = () => { if (typeof reader.result === 'string') { resolve(reader.result.replace('data:', '').replace(/^.+,/, '')); } }; reader.readAsDataURL(file); }); }

IndexOutOfMJ avatar Jul 23 '24 20:07 IndexOutOfMJ

My best guess at this is that you're somehow loading the older nbt-ts library instead of @enginehub/nbt-ts, or some other such type mismatch is occurring. I'm personally unable to reproduce this. If you could provide a minimal project that reproduces the issue, that would be helpful. Otherwise, I would recommend double-checking the versions of everything.

octylFractal avatar Jul 23 '24 20:07 octylFractal

Okay, the only two packages i'm using in this context are those:

"@enginehub/schematicwebviewer": "^4.9.0",
"buffer": "^6.0.3",

Can you approve this ?

IndexOutOfMJ avatar Jul 23 '24 21:07 IndexOutOfMJ

I also ran into this same issue. To replicate i created a new Vite Project Added latest SchematicWebViewer, buffer, and blob-to-base64

This is my JS code

import {renderSchematic} from "@enginehub/schematicwebviewer";
import {Buffer} from "buffer";
import blobToBase64 from "blob-to-base64";

globalThis.Buffer = Buffer;

let temp = await fetch("./schem.schem")

let schematic = blobToBase64(await temp.blob(),(r,o)=>render(o))

function render(schematic) {
schematic = schematic.substring(37)
alert(schematic)
renderSchematic(document.querySelector('#schematicRenderer'),schematic , {
size: 500,
renderArrow: false,
renderBars: false,
corsBypassUrl: 'https://corsproxy.io/?',
});
}

DanielSchmerber avatar Aug 08 '24 07:08 DanielSchmerber

in general this error means the NBT data is invalid. in your provided code i'm a bit confused by the random substring call there?

me4502 avatar Aug 08 '24 07:08 me4502

Yeah, that was the base64 api adding metadata about the encoding to the string, should have commented that

DanielSchmerber avatar Aug 08 '24 07:08 DanielSchmerber

I managed to find the Root of this issue

The Problem is the getTagType function of the tag.js file. a transative dependency of SchematicJS

it checks what type the tag is instanceof.

However the function receives an object with following format ```{value:"examplevalue"}```` I added a unwrap to this function, and got it working again

if(tag instanceof Object){
        tag = tag.value;
}````

DanielSchmerber avatar Aug 08 '24 08:08 DanielSchmerber

hmm, is that from a deeply nested tag, or the root tag? i wonder if this is just an issue around root tag handling, as that differs between Sponge Schematic v2 & v3

me4502 avatar Aug 12 '24 12:08 me4502

I printed the object that is being passed into the function to the console using console.dir grafik

It is instanceof Int2, wich is not being tested for in the getTagType function. It is the only time getTagType is called when displaying a schematic using SchematicWebviewer I noticed the code in my previous comment is faulty and only fixed this specific usecase

DanielSchmerber avatar Aug 12 '24 13:08 DanielSchmerber

So is there a way to fix this problem ?

IndexOutOfMJ avatar Aug 17 '24 14:08 IndexOutOfMJ