Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Added better load error displaying.
Browse files Browse the repository at this point in the history
"Fixed" bug were images could fail to load when reading tiny mipmaps, in that I now completely ignore them.
  • Loading branch information
KFreon committed Feb 2, 2017
1 parent f72461b commit 3405b4b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CSharpImageLibrary/DDS/DDSGeneral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ private static MipMap ReadUncompressedMipMap(MemoryStream stream, int mipOffset,
{
byte[] data = stream.GetBuffer();
byte[] mipmap = new byte[mipHeight * mipWidth * 4 * formatDetails.ComponentSize];
DDS_Decoders.ReadUncompressed(data, mipOffset, mipmap, mipWidth * mipHeight, ddspf, formatDetails);

// Smaller sizes breaks things, so just exclude them
if (mipHeight >= 4 && mipWidth >= 4)
DDS_Decoders.ReadUncompressed(data, mipOffset, mipmap, mipWidth * mipHeight, ddspf, formatDetails);

return new MipMap(mipmap, mipWidth, mipHeight, formatDetails);
}
Expand Down
2 changes: 1 addition & 1 deletion UI_Project/NewMainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@

<Style.Triggers>
<DataTrigger Binding="{Binding LoadFailed}" Value="True">
<Setter Property="Content" Value="Load failed!"/>
<Setter Property="Content" Value="{Binding LoadFailError}"/>
<Setter Property="FontSize" Value="10"/>
<Setter Property="BorderBrush" Value="Red"/>
</DataTrigger>
Expand Down
18 changes: 17 additions & 1 deletion UI_Project/NewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,19 @@ public bool LoadFailed
}
}

string loadFailError = null;
public string LoadFailError
{
get
{
return loadFailError;
}
set
{
SetProperty(ref loadFailError, value);
}
}


bool isImageLoaded = false;
public bool IsImageLoaded
Expand Down Expand Up @@ -1162,7 +1175,8 @@ internal async Task LoadImage(string path)
}
catch (Exception e)
{
Trace.WriteLine($"Failed to read image from disk: {e.Message}");
Trace.WriteLine($"IO failure when reading image from disk: {e.Message}");
LoadFailError = $"IO failure.{Environment.NewLine} {e.Message}";
LoadFailed = true;
return;
}
Expand Down Expand Up @@ -1195,6 +1209,7 @@ internal async Task<bool> LoadImage(byte[] data)
}
catch(Exception e)
{
LoadFailError = e.Message;
LoadFailed = true;
return false;
}
Expand Down Expand Up @@ -1262,6 +1277,7 @@ void CloseImage(bool updateUI)
BulkConvertFailed.Clear();
MergeChannelsImages.Clear();
LoadFailed = false;
LoadFailError = null;
previousAlphaSetting = AlphaDisplaySettings.PremultiplyAlpha;
SavePanelOpen = false;

Expand Down

0 comments on commit 3405b4b

Please sign in to comment.