diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs index fdddbf823..287df0e95 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/GltfData.cs @@ -39,32 +39,12 @@ namespace UniGLTF /// public glTF GLTF { get; } - public NativeArray? _bin; - /// /// BIN chunk /// > This chunk MUST be the second chunk of the Binary glTF asset /// /// - public NativeArray Bin - { - get - { - if (!_bin.HasValue) - { - // init - if (Chunks != null) - { - if (Chunks.Count >= 2) - { - _bin = CreateNativeArray(Chunks[1].Bytes); - } - } - - } - return _bin.GetValueOrDefault(); - } - } + public NativeArray Bin { get; } /// /// Migration Flags used by ImporterContext @@ -83,6 +63,8 @@ namespace UniGLTF /// Dictionary> _UriCache = new Dictionary>(); + List m_disposables = new List(); + public GltfData(string targetPath, string json, glTF gltf, IReadOnlyList chunks, IStorage storage, MigrationFlags migrationFlags) { TargetPath = targetPath; @@ -91,6 +73,25 @@ namespace UniGLTF Chunks = chunks; _storage = storage; MigrationFlags = migrationFlags; + + // init + if (Chunks != null) + { + if (Chunks.Count >= 2) + { + Bin = CreateNativeArray(Chunks[1].Bytes); + } + } + } + + public void Dispose() + { + foreach (var disposable in m_disposables) + { + disposable.Dispose(); + } + m_disposables.Clear(); + _UriCache.Clear(); } public static GltfData CreateFromExportForTest(ExportingGltfData data) @@ -403,18 +404,5 @@ namespace UniGLTF array.CopyFrom(data); return array; } - - List m_disposables = new List(); - - public void Dispose() - { - foreach (var disposable in m_disposables) - { - disposable.Dispose(); - } - m_disposables.Clear(); - _UriCache.Clear(); - _bin = null; - } } }