Skip to content

Commit

Permalink
[HaCrerator] Check map loading exceptions too! & log
Browse files Browse the repository at this point in the history
  • Loading branch information
lastbattle committed Dec 20, 2020
1 parent c5a1c74 commit 8c6bf8c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
47 changes: 31 additions & 16 deletions HaCreator/GUI/Initialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public partial class Initialization : System.Windows.Forms.Form
public Initialization()
{
InitializeComponent();

#if RELEASE
debugButton.Visible = false;
#endif
}

private bool IsPathCommon(string path)
Expand Down Expand Up @@ -278,22 +274,36 @@ private void debugButton_Click(object sender, EventArgs e)
}
MapLoader.VerifyMapPropsKnown(mapImage, true);
MapInfo info = new MapInfo(mapImage, null, null, null);
MapLoader.LoadMisc(mapImage, board);

List<BackgroundInstance> allBackgrounds = new List<BackgroundInstance>();
allBackgrounds.AddRange(board.BoardItems.BackBackgrounds);
allBackgrounds.AddRange(board.BoardItems.FrontBackgrounds);
foreach (BackgroundInstance bg in allBackgrounds)
try
{
if (bg.type != MapleLib.WzLib.WzStructure.Data.BackgroundType.Regular)
if (bg.cx < 0 || bg.cy < 0)
{
string error = string.Format("Negative CX/ CY moving background object. CX='{0}', CY={1}, Type={2}, {3}{4}", bg.cx, bg.cy, bg.type.ToString(), Environment.NewLine, mapImage.ToString() /*overrides, see WzImage.ToString*/);
MapLoader.LoadBackgrounds(mapImage, board);
MapLoader.LoadMisc(mapImage, board);

MapleLib.Helpers.ErrorLogger.Log(ErrorLevel.Critical, error);
// Check background to ensure that its correct
List<BackgroundInstance> allBackgrounds = new List<BackgroundInstance>();
allBackgrounds.AddRange(board.BoardItems.BackBackgrounds);
allBackgrounds.AddRange(board.BoardItems.FrontBackgrounds);

foreach (BackgroundInstance bg in allBackgrounds)
{
if (bg.type != MapleLib.WzLib.WzStructure.Data.BackgroundType.Regular)
{
if (bg.cx < 0 || bg.cy < 0)
{
string error = string.Format("Negative CX/ CY moving background object. CX='{0}', CY={1}, Type={2}, {3}{4}", bg.cx, bg.cy, bg.type.ToString(), Environment.NewLine, mapImage.ToString() /*overrides, see WzImage.ToString*/);
ErrorLogger.Log(ErrorLevel.IncorrectStructure, error);
}
}
}
allBackgrounds.Clear();
board.BoardItems.BackBackgrounds.Clear();
board.BoardItems.FrontBackgrounds.Clear();
}
catch (Exception exp)
{
string error = string.Format("Exception occured loading {0}{1}{2}{3}{4}", mapcat, Environment.NewLine, mapImage.ToString() /*overrides, see WzImage.ToString*/, Environment.NewLine, exp.ToString());
ErrorLogger.Log(ErrorLevel.Crash, error);
}
allBackgrounds.Clear();

mapImage.UnparseImage(); // To preserve memory, since this is a very memory intensive test
}
Expand All @@ -305,6 +315,11 @@ private void debugButton_Click(object sender, EventArgs e)
MessageBox.Show("Check for map errors completed. See 'Debug_errors.txt' for more information.");
}

/// <summary>
/// Keyboard navigation
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Initialization_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
Expand Down
24 changes: 12 additions & 12 deletions HaCreator/GUI/Initialization.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8c6bf8c

Please sign in to comment.