Skip to content

Commit

Permalink
NullReferenceException fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanMurzak committed May 10, 2024
1 parent c1d830e commit 1e8ad15
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Assets/_PackageRoot/Runtime/Future/Future.ThenSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static Future<Sprite> ThenSet(this Future<Sprite> future, params Image[]
/// <param name="images">Array of RawImages</param>
/// <returns>Returns async Future</returns>
public static Future<Sprite> ThenSet(this Future<Sprite> future, params RawImage[] rawImages)
=> future.ThenSet((target, sprite) => target.texture = sprite.texture, rawImages);
=> future.ThenSet((target, sprite) => target.texture = sprite?.texture, rawImages);

/// <summary>
/// Set image into array of SpriteRenderers
Expand All @@ -93,6 +93,6 @@ public static Future<Sprite> ThenSet(this Future<Sprite> future, params SpriteRe
/// <param name="images">Array of Materials</param>
/// <returns>Returns async Future</returns>
public static Future<Sprite> ThenSet(this Future<Sprite> future, string propertyName = "_MainTex", params Material[] materials)
=> future.ThenSet((target, sprite) => target.SetTexture(propertyName, sprite.texture), materials);
=> future.ThenSet((target, sprite) => target.SetTexture(propertyName, sprite?.texture), materials);
}
}
10 changes: 5 additions & 5 deletions Assets/_PackageRoot/Runtime/Future/Future.ThenSetRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Future<Reference<Sprite>> ThenSet<T>(this Future<Reference<Sprite>
setter?.Invoke(target, reference);
if (target is Component monoBehaviour)
reference.AddTo(monoBehaviour.GetCancellationTokenOnDestroy());
reference?.AddTo(monoBehaviour.GetCancellationTokenOnDestroy());
}
});
});
Expand All @@ -59,30 +59,30 @@ public static Future<Reference<Sprite>> ThenSet<T>(this Future<Reference<Sprite>
/// <param name="images">Array of Images</param>
/// <returns>Returns async Future</returns>
public static Future<Reference<Sprite>> ThenSet(this Future<Reference<Sprite>> future, params Image[] images)
=> future.ThenSet((target, reference) => target.sprite = reference.Value, images);
=> future.ThenSet((target, reference) => target.sprite = reference?.Value, images);

/// <summary>
/// Set image into array of RawImages
/// </summary>
/// <param name="images">Array of RawImages</param>
/// <returns>Returns async Future</returns>
public static Future<Reference<Sprite>> ThenSet(this Future<Reference<Sprite>> future, params RawImage[] rawImages)
=> future.ThenSet((target, reference) => target.texture = reference.Value.texture, rawImages);
=> future.ThenSet((target, reference) => target.texture = reference?.Value?.texture, rawImages);

/// <summary>
/// Set image into array of SpriteRenderers
/// </summary>
/// <param name="images">Array of SpriteRenderers</param>
/// <returns>Returns async Future</returns>
public static Future<Reference<Sprite>> ThenSet(this Future<Reference<Sprite>> future, params SpriteRenderer[] spriteRenderers)
=> future.ThenSet((target, reference) => target.sprite = reference.Value, spriteRenderers);
=> future.ThenSet((target, reference) => target.sprite = reference?.Value, spriteRenderers);

/// <summary>
/// Set image into array of Materials
/// </summary>
/// <param name="images">Array of Materials</param>
/// <returns>Returns async Future</returns>
public static Future<Reference<Sprite>> ThenSet(this Future<Reference<Sprite>> future, string propertyName = "_MainTex", params Material[] materials)
=> future.ThenSet((target, reference) => target.SetTexture(propertyName, reference.Value.texture), materials);
=> future.ThenSet((target, reference) => target.SetTexture(propertyName, reference?.Value?.texture), materials);
}
}
2 changes: 1 addition & 1 deletion Assets/_PackageRoot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Ivan Murzak",
"url": "https://github.com/IvanMurzak"
},
"version": "5.1.1",
"version": "5.1.2",
"unity": "2019.2",
"description": "Asynchronous image loading from remote or local destination. It has two layers of configurable Memory and Disk cache systems.",
"dependencies": {
Expand Down

0 comments on commit 1e8ad15

Please sign in to comment.