From 4068b15d9f6a6f11caab3aa9c7afae0b724b3be0 Mon Sep 17 00:00:00 2001 From: Petur Darri Petursson Date: Mon, 20 Aug 2018 19:39:02 +0000 Subject: [PATCH] Changed how cover images are loaded, to fix an occasional crash. --- SongLoaderPlugin/Plugin.cs | 2 +- SongLoaderPlugin/Properties/AssemblyInfo.cs | 4 ++-- SongLoaderPlugin/SongLoader.cs | 26 ++++++++------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/SongLoaderPlugin/Plugin.cs b/SongLoaderPlugin/Plugin.cs index 1e1c698..302016f 100644 --- a/SongLoaderPlugin/Plugin.cs +++ b/SongLoaderPlugin/Plugin.cs @@ -6,7 +6,7 @@ namespace SongLoaderPlugin { public class Plugin : IPlugin { - public const string VersionNumber = "v4.3.0"; + public const string VersionNumber = "v4.3.1"; public string Name { diff --git a/SongLoaderPlugin/Properties/AssemblyInfo.cs b/SongLoaderPlugin/Properties/AssemblyInfo.cs index c0646ff..d04db80 100644 --- a/SongLoaderPlugin/Properties/AssemblyInfo.cs +++ b/SongLoaderPlugin/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("4.3.0")] -[assembly: AssemblyFileVersion("4.3.0")] \ No newline at end of file +[assembly: AssemblyVersion("4.3.1")] +[assembly: AssemblyFileVersion("4.3.1")] \ No newline at end of file diff --git a/SongLoaderPlugin/SongLoader.cs b/SongLoaderPlugin/SongLoader.cs index 7d8f4ec..7fa2724 100644 --- a/SongLoaderPlugin/SongLoader.cs +++ b/SongLoaderPlugin/SongLoader.cs @@ -8,7 +8,6 @@ using SimpleJSON; using SongLoaderPlugin.Internals; using SongLoaderPlugin.OverrideClasses; -using UnityEngine.Networking; using UnityEngine.SceneManagement; namespace SongLoaderPlugin @@ -318,26 +317,21 @@ private void RemoveCustomScores() scores.RemoveAll(x => scoresToRemove.Contains(x)); } - private IEnumerator LoadSprite(string spritePath, CustomLevel customLevel) + private void LoadSprite(string spritePath, CustomLevel customLevel) { Sprite sprite; if (!LoadedSprites.ContainsKey(spritePath)) { - using (var web = UnityWebRequestTexture.GetTexture(EncodePath(spritePath), true)) + var bytes = File.ReadAllBytes(spritePath); + var tex = new Texture2D(256, 256); + if (!tex.LoadImage(bytes, true)) { - yield return web.SendWebRequest(); - if (web.isNetworkError || web.isHttpError) - { - Log("Error loading: " + spritePath + ": " + web.error, LogSeverity.Warn); - sprite = null; - } - else - { - var tex = DownloadHandlerTexture.GetContent(web); - sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f, 100, 1); - LoadedSprites.Add(spritePath, sprite); - } + Log("Failed to load cover image: " + spritePath); + return; } + + sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.one * 0.5f, 100, 1); + LoadedSprites.Add(spritePath, sprite); } else { @@ -598,7 +592,7 @@ private CustomLevel LoadSong(CustomSongInfo song) newLevel.SetDifficultyBeatmaps(difficultyBeatmaps.ToArray()); newLevel.InitData(); - StartCoroutine(LoadSprite("file:///" + song.path + "/" + song.coverImagePath, newLevel)); + LoadSprite(song.path + "/" + song.coverImagePath, newLevel); return newLevel; } catch (Exception e)