Siccity / GLTFUtility

Simple GLTF importer for Unity
MIT License
977 stars 217 forks source link

json chunk could not be obtained properly when parsing GLB with unicode character content #195

Open hunterforesee opened 2 years ago

hunterforesee commented 2 years ago

// In GetGLBJson Method(Importer.cs), json is read via TextReader, it does not works properly when json string containg unicode character; //

private static string GetGLBJson(Stream stream, out long binChunkStart) { ‘’‘’ TextReader reader = new StreamReader(stream); char[] jsonChars = new char[chunkLength]; reader.Read(jsonChars, 0, (int) chunkLength); string json = new string(jsonChars); ‘’‘’
}

//May be It Should be Written Like this,Using Stream.Read Method private static string GetGLBJson(Stream stream, out long binChunkStart) { ‘’‘’ byte[] jsonBytes = new byte[chunkLength]; stream.Read(jsonBytes, 0, (int) chunkLength); string json = Encoding.Default.GetString(jsonBytes); ‘’‘’
}

stetttho commented 2 years ago

I think I faced the same problem, always got an error about illegal characters at the end of the returned JSON.

I first solved it differently by placing

int index = json.LastIndexOf("}");
json = json.Remove(index + 1);

at the very top of the LoadAsync method in Importer.cs.

But now I tried your solution and it also works and surely is the cleaner way to go. You should make a PR with it.

Fragilem17 commented 2 years ago

Tried the top solution and worked perfectly. Had the same issue before.

gavlenamdev commented 1 year ago

Yes, Whenever the model has Unicode characters, getting this error. and @hunterforesee solution worked perfectly. Did anyone create PR?