Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid tag value #25

Open
IndexOutOfMJ opened this issue Jul 23, 2024 · 13 comments
Open

Invalid tag value #25

IndexOutOfMJ opened this issue Jul 23, 2024 · 13 comments

Comments

@IndexOutOfMJ
Copy link

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/'
      });
@octylFractal
Copy link
Member

Can you provide the files you tested?

@IndexOutOfMJ
Copy link
Author

IndexOutOfMJ commented Jul 23, 2024

@octylFractal
Copy link
Member

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

@IndexOutOfMJ
Copy link
Author

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); }); }

@octylFractal
Copy link
Member

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.

@IndexOutOfMJ
Copy link
Author

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 ?

@DanielSchmerber
Copy link

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/?',
});
}

@me4502
Copy link
Member

me4502 commented Aug 8, 2024

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?

@DanielSchmerber
Copy link

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

@DanielSchmerber
Copy link

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;
}````

@me4502
Copy link
Member

me4502 commented Aug 12, 2024

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

@DanielSchmerber
Copy link

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

@IndexOutOfMJ
Copy link
Author

So is there a way to fix this problem ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants