1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

Fixed UiParser ImageExceptionHandler being ignored when an exception occurs during texture construction

This commit is contained in:
Ell 2024-11-09 18:01:52 +01:00
parent a58470de9f
commit e1e1e8db8c
2 changed files with 22 additions and 11 deletions

View file

@ -32,6 +32,7 @@ Fixes
- Fixed tooltips not being bounded correctly for viewports that don't start at the origin - Fixed tooltips not being bounded correctly for viewports that don't start at the origin
- Fixed a stack overflow exception when a panel's children have just enough height to cause a scroll bar to appear - Fixed a stack overflow exception when a panel's children have just enough height to cause a scroll bar to appear
- Fixed AddedToUi and RemovedFromUi being called for freshly added or removed children whose parents are not in a ui system - Fixed AddedToUi and RemovedFromUi being called for freshly added or removed children whose parents are not in a ui system
- Fixed UiParser ImageExceptionHandler being ignored when an exception occurs during texture construction
### MLEM.Data ### MLEM.Data
Improvements Improvements

View file

@ -154,18 +154,24 @@ namespace MLEM.Ui.Parsers {
lock (bytesLock) lock (bytesLock)
bytesNull = bytes == null; bytesNull = bytes == null;
if (!bytesNull) { if (!bytesNull) {
Texture2D tex; Texture2D tex = null;
lock (bytesLock) { lock (bytesLock) {
try {
using (var stream = new MemoryStream(bytes)) { using (var stream = new MemoryStream(bytes)) {
using (var read = Texture2D.FromStream(this.GraphicsDevice, stream)) using (var read = Texture2D.FromStream(this.GraphicsDevice, stream))
tex = read.PremultipliedCopy(); tex = read.PremultipliedCopy();
} }
} catch (Exception e) {
CatchOrRethrow(e);
}
bytes = null; bytes = null;
} }
if (tex != null) {
image = new TextureRegion(tex); image = new TextureRegion(tex);
onImageFetched?.Invoke(image); onImageFetched?.Invoke(image);
} }
} }
}
return image; return image;
}) { }) {
SetHeightBasedOnAspect = true, SetHeightBasedOnAspect = true,
@ -211,6 +217,11 @@ namespace MLEM.Ui.Parsers {
lock (bytesLock) lock (bytesLock)
bytes = src; bytes = src;
} catch (Exception e) { } catch (Exception e) {
CatchOrRethrow(e);
}
}
void CatchOrRethrow(Exception e) {
if (this.ImageExceptionHandler != null) { if (this.ImageExceptionHandler != null) {
this.ImageExceptionHandler.Invoke(path, e); this.ImageExceptionHandler.Invoke(path, e);
} else { } else {
@ -218,7 +229,6 @@ namespace MLEM.Ui.Parsers {
} }
} }
} }
}
/// <summary> /// <summary>
/// A flags enumeration used by <see cref="UiParser"/> that contains the types of elements that can be parsed and returned in <see cref="Parse"/> or <see cref="ParseInto"/>. /// A flags enumeration used by <see cref="UiParser"/> that contains the types of elements that can be parsed and returned in <see cref="Parse"/> or <see cref="ParseInto"/>.