Skip to content
This repository has been archived by the owner on Sep 30, 2019. It is now read-only.

Commit

Permalink
Changed how cover images are loaded, to fix an occasional crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeturDarri committed Aug 20, 2018
1 parent c2a7561 commit 4068b15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion SongLoaderPlugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions SongLoaderPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[assembly: AssemblyVersion("4.3.1")]
[assembly: AssemblyFileVersion("4.3.1")]
26 changes: 10 additions & 16 deletions SongLoaderPlugin/SongLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using SimpleJSON;
using SongLoaderPlugin.Internals;
using SongLoaderPlugin.OverrideClasses;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

namespace SongLoaderPlugin
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4068b15

Please sign in to comment.