Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 084758e

Browse files
committed
fix image loading error: when an image fails to be loaded and initiated correctly, we should Assert the error in debug Mode and handle this situation by workaround in release Mode
1 parent 0cdac01 commit 084758e

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Runtime/ui/painting/image.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public Image(Texture texture, bool noDispose = false, bool isAsset = false, Asse
2323
this._isDynamic = isDynamic;
2424
}
2525

26+
public bool valid {
27+
get { return this._texture != null; }
28+
}
29+
2630
public int width {
2731
get { return this._texture != null ? this._texture.width : 0; }
2832
}

Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,11 @@ void _drawPath(uiPath path, uiPaint paint) {
686686
}
687687

688688
void _drawImage(Image image, uiOffset offset, uiPaint paint) {
689-
D.assert(image != null);
689+
D.assert(image != null && image.valid);
690+
691+
if (image == null || !image.valid) {
692+
return;
693+
}
690694

691695
this._drawImageRect(image,
692696
null,
@@ -698,7 +702,11 @@ void _drawImage(Image image, uiOffset offset, uiPaint paint) {
698702
}
699703

700704
void _drawImageRect(Image image, uiRect? src, uiRect dst, uiPaint paint) {
701-
D.assert(image != null);
705+
D.assert(image != null && image.valid);
706+
707+
if (image == null || !image.valid) {
708+
return;
709+
}
702710

703711
if (src == null) {
704712
src = uiRectHelper.one;
@@ -719,7 +727,11 @@ void _drawImageRect(Image image, uiRect? src, uiRect dst, uiPaint paint) {
719727
}
720728

721729
void _drawImageNine(Image image, uiRect? src, uiRect center, uiRect dst, uiPaint paint) {
722-
D.assert(image != null);
730+
D.assert(image != null && image.valid);
731+
732+
if (image == null || !image.valid) {
733+
return;
734+
}
723735

724736
var scaleX = 1f / image.width;
725737
var scaleY = 1f / image.height;

0 commit comments

Comments
 (0)