From 141a3c4cecbfe8f6ea4ef5714700511d477177de Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Feb 2022 13:20:20 +0900 Subject: [PATCH] =?UTF-8?q?Dispose=20=E5=91=BC=E3=81=B3=E5=BF=98=E3=82=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details. --- .../VRM/Editor/Format/vrmAssetPostprocessor.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Assets/VRM/Editor/Format/vrmAssetPostprocessor.cs b/Assets/VRM/Editor/Format/vrmAssetPostprocessor.cs index 29c2d3676..0ae4e0f24 100644 --- a/Assets/VRM/Editor/Format/vrmAssetPostprocessor.cs +++ b/Assets/VRM/Editor/Format/vrmAssetPostprocessor.cs @@ -45,18 +45,25 @@ namespace VRM throw new Exception(); } - var data = new GlbFileParser(vrmPath.FullPath).Parse(); - var vrm = new VRMData(data); - var prefabPath = vrmPath.Parent.Child(vrmPath.FileNameWithoutExtension + ".prefab"); + /// + /// これは EditorApplication.delayCall により呼び出される。 + /// + /// * delayCall には UnityEngine.Object 持ち越すことができない + /// * vrmPath のみを持ち越す + /// + /// + /// Action> onCompleted = texturePaths => { var map = texturePaths .Select(x => x.LoadAsset()) .ToDictionary(x => new SubAssetKey(x), x => x as UnityEngine.Object); - using (var context = new VRMImporterContext(vrm, externalObjectMap: map)) + // 確実に Dispose するために敢えて再パースしている + using (var data = new GlbFileParser(vrmPath.FullPath).Parse()) + using (var context = new VRMImporterContext(new VRMData(data), externalObjectMap: map)) { var editor = new VRMEditorImporterContext(context, prefabPath); foreach (var textureInfo in context.TextureDescriptorGenerator.Get().GetEnumerable()) @@ -69,7 +76,8 @@ namespace VRM }; // extract texture images - using (var context = new VRMImporterContext(vrm)) + using (var data = new GlbFileParser(vrmPath.FullPath).Parse()) + using (var context = new VRMImporterContext(new VRMData(data))) { var editor = new VRMEditorImporterContext(context, prefabPath); editor.ConvertAndExtractImages(onCompleted);