From 065c13f498b65e444fa7de944b96cdf44c0cdfd1 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 21 Jan 2019 15:06:02 +0100 Subject: [PATCH 1/3] [unity] Fixed skeleton binary import, was broken by recent changes. Closes #1259. --- .../Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs index 787a1ba76..61e86e711 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs @@ -566,10 +566,10 @@ namespace Spine.Unity.Editor { SkeletonBinary binary = new SkeletonBinary(new AtlasRequirementLoader(requiredPaths)); Stream input = null; TextAsset data = AssetDatabase.LoadAssetAtPath(skeletonDataPath); - if (data != null) { + if (data == null) { // On a "Reimport All" the order of imports can be wrong, thus LoadAssetAtPath() above could return null. // as a workaround, we provide a fallback reader. - input = File.Open(skeletonDataPath, FileMode.Open); + input = File.Open(skeletonDataPath, FileMode.Open, FileAccess.Read); } else { input = new MemoryStream(data.bytes); From 68eeed67b8bdb0d2fb89b9872ba0b7dc4f7474a9 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 22 Jan 2019 11:27:47 +0100 Subject: [PATCH 2/3] [unity] Added using and finally-dispose guards around all stream instances, see #1260. --- .../Editor/SpineEditorUtilities.cs | 47 ++++++++++++------- .../Asset Types/SkeletonDataAsset.cs | 11 +++-- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs index 61e86e711..89b2aaa77 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs @@ -514,17 +514,24 @@ namespace Spine.Unity.Editor { TextReader reader = null; TextAsset spineJson = AssetDatabase.LoadAssetAtPath(skeletonDataPath); - if (spineJson != null) { - reader = new StringReader(spineJson.text); + Dictionary root = null; + try { + if (spineJson != null) { + reader = new StringReader(spineJson.text); + } + else { + // On a "Reimport All" the order of imports can be wrong, thus LoadAssetAtPath() above could return null. + // as a workaround, we provide a fallback reader. + reader = new StreamReader(skeletonDataPath); + } + root = Json.Deserialize(reader) as Dictionary; } - else { - // On a "Reimport All" the order of imports can be wrong, thus LoadAssetAtPath() above could return null. - // as a workaround, we provide a fallback reader. - reader = new StreamReader(skeletonDataPath); + finally { + if (reader != null) + reader.Dispose(); } - var root = Json.Deserialize(reader) as Dictionary; - if (!root.ContainsKey("skins")) + if (root == null || !root.ContainsKey("skins")) return requiredPaths; foreach (var skin in (Dictionary)root["skins"]) { @@ -566,15 +573,21 @@ namespace Spine.Unity.Editor { SkeletonBinary binary = new SkeletonBinary(new AtlasRequirementLoader(requiredPaths)); Stream input = null; TextAsset data = AssetDatabase.LoadAssetAtPath(skeletonDataPath); - if (data == null) { - // On a "Reimport All" the order of imports can be wrong, thus LoadAssetAtPath() above could return null. - // as a workaround, we provide a fallback reader. - input = File.Open(skeletonDataPath, FileMode.Open, FileAccess.Read); + try { + if (data != null) { + input = new MemoryStream(data.bytes); + } + else { + // On a "Reimport All" the order of imports can be wrong, thus LoadAssetAtPath() above could return null. + // as a workaround, we provide a fallback reader. + input = File.Open(skeletonDataPath, FileMode.Open, FileAccess.Read); + } + binary.ReadSkeletonData(input); } - else { - input = new MemoryStream(data.bytes); + finally { + if (input != null) + input.Dispose(); } - binary.ReadSkeletonData(input); binary = null; } @@ -1000,7 +1013,9 @@ namespace Spine.Unity.Editor { int[][] compatibleVersions; if (asset.name.Contains(".skel")) { try { - rawVersion = SkeletonBinary.GetVersionString(new MemoryStream(asset.bytes)); + using (var memStream = new MemoryStream(asset.bytes)) { + rawVersion = SkeletonBinary.GetVersionString(memStream); + } isSpineData = !(string.IsNullOrEmpty(rawVersion)); compatibleVersions = compatibleBinaryVersions; } catch (System.Exception e) { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs index fe2f90b12..8069c0070 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs @@ -219,11 +219,12 @@ namespace Spine.Unity { } internal static SkeletonData ReadSkeletonData (byte[] bytes, AttachmentLoader attachmentLoader, float scale) { - var input = new MemoryStream(bytes); - var binary = new SkeletonBinary(attachmentLoader) { - Scale = scale - }; - return binary.ReadSkeletonData(input); + using (var input = new MemoryStream(bytes)) { + var binary = new SkeletonBinary(attachmentLoader) { + Scale = scale + }; + return binary.ReadSkeletonData(input); + } } internal static SkeletonData ReadSkeletonData (string text, AttachmentLoader attachmentLoader, float scale) { From 1dc7bbc5fa4298b7b5ecf75b98eb49b2389c5aa5 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 22 Jan 2019 12:27:00 +0100 Subject: [PATCH 3/3] [unity] Fixed PointFollower error message on script rebuild, closes #1261. --- .../Spine/Runtime/spine-unity/Components/PointFollower.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/PointFollower.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/PointFollower.cs index 91570a00c..2cc6878b2 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/PointFollower.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/PointFollower.cs @@ -90,7 +90,7 @@ namespace Spine.Unity { bone = null; point = null; if (!string.IsNullOrEmpty(pointAttachmentName)) { - var skeleton = skeletonRenderer.skeleton; + var skeleton = skeletonRenderer.Skeleton; int slotIndex = skeleton.FindSlotIndex(slotName); if (slotIndex >= 0) {