mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-21 20:43:29 +01:00
Fixed UiParser ImageExceptionHandler being ignored when an exception occurs during texture construction
This commit is contained in:
parent
a58470de9f
commit
e1e1e8db8c
2 changed files with 22 additions and 11 deletions
|
@ -32,6 +32,7 @@ Fixes
|
|||
- 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 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
|
||||
Improvements
|
||||
|
|
|
@ -154,16 +154,22 @@ namespace MLEM.Ui.Parsers {
|
|||
lock (bytesLock)
|
||||
bytesNull = bytes == null;
|
||||
if (!bytesNull) {
|
||||
Texture2D tex;
|
||||
Texture2D tex = null;
|
||||
lock (bytesLock) {
|
||||
using (var stream = new MemoryStream(bytes)) {
|
||||
using (var read = Texture2D.FromStream(this.GraphicsDevice, stream))
|
||||
tex = read.PremultipliedCopy();
|
||||
try {
|
||||
using (var stream = new MemoryStream(bytes)) {
|
||||
using (var read = Texture2D.FromStream(this.GraphicsDevice, stream))
|
||||
tex = read.PremultipliedCopy();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CatchOrRethrow(e);
|
||||
}
|
||||
bytes = null;
|
||||
}
|
||||
image = new TextureRegion(tex);
|
||||
onImageFetched?.Invoke(image);
|
||||
if (tex != null) {
|
||||
image = new TextureRegion(tex);
|
||||
onImageFetched?.Invoke(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
|
@ -211,11 +217,15 @@ namespace MLEM.Ui.Parsers {
|
|||
lock (bytesLock)
|
||||
bytes = src;
|
||||
} catch (Exception e) {
|
||||
if (this.ImageExceptionHandler != null) {
|
||||
this.ImageExceptionHandler.Invoke(path, e);
|
||||
} else {
|
||||
throw new NullReferenceException($"Couldn't parse image {path}, and no ImageExceptionHandler was set", e);
|
||||
}
|
||||
CatchOrRethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
void CatchOrRethrow(Exception e) {
|
||||
if (this.ImageExceptionHandler != null) {
|
||||
this.ImageExceptionHandler.Invoke(path, e);
|
||||
} else {
|
||||
throw new NullReferenceException($"Couldn't parse image {path}, and no ImageExceptionHandler was set", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue