mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 11:28:35 -05:00
GlbParseException を作りました
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace UniGLTF
|
||||
@@ -14,7 +13,7 @@ namespace UniGLTF
|
||||
|
||||
public static GlbChunkType ToChunkType(this string src)
|
||||
{
|
||||
switch(src)
|
||||
switch (src)
|
||||
{
|
||||
case "BIN":
|
||||
return GlbChunkType.BIN;
|
||||
@@ -53,27 +52,27 @@ namespace UniGLTF
|
||||
//
|
||||
if (bytes.Length < 12)
|
||||
{
|
||||
throw new FormatException("not glb header");
|
||||
throw new GlbParseException("glb header not found");
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
if (Encoding.ASCII.GetString(bytes, 0, 4) != GLB_MAGIC)
|
||||
{
|
||||
throw new FormatException("invalid magic");
|
||||
throw new GlbParseException("invalid magic");
|
||||
}
|
||||
pos += 4;
|
||||
|
||||
var version = BitConverter.ToUInt32(bytes, pos);
|
||||
if (version != GLB_VERSION)
|
||||
{
|
||||
throw new FormatException($"unknown version: {version}");
|
||||
throw new GlbParseException($"unknown version: {version}");
|
||||
}
|
||||
pos += 4;
|
||||
|
||||
var totalLength = BitConverter.ToUInt32(bytes, pos);
|
||||
if (bytes.Length < totalLength)
|
||||
{
|
||||
throw new System.IO.EndOfStreamException($"Not enough size: {bytes.Length} < {totalLength}");
|
||||
throw new GlbParseException($"not enough size: {bytes.Length} < {totalLength}");
|
||||
}
|
||||
pos += 4;
|
||||
|
||||
|
||||
@@ -14,4 +14,12 @@ namespace UniGLTF
|
||||
public UniGLTFNotSupportedException(string fmt, params object[] args) : this(string.Format(fmt, args)) { }
|
||||
public UniGLTFNotSupportedException(string msg) : base(msg) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exception in parse the glb header
|
||||
/// </summary>
|
||||
public class GlbParseException : UniGLTFException
|
||||
{
|
||||
public GlbParseException(string msg) : base(msg) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace UniGLTF
|
||||
// glb header + 1st chunk only
|
||||
var mod = bytes.Take(12 + 8 + data.Chunks[0].Bytes.Count).ToArray();
|
||||
|
||||
Assert.Throws<EndOfStreamException>(() =>
|
||||
Assert.Throws<GlbParseException>(() =>
|
||||
{
|
||||
// 再パース
|
||||
var data2 = new GlbBinaryParser(mod, Path.GetFileNameWithoutExtension(path)).Parse();
|
||||
|
||||
Reference in New Issue
Block a user