Skip to content

Commit

Permalink
general error handling to stop people breaking everything horribly
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamford committed Jan 30, 2014
1 parent b4c5039 commit 0e39c2d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Starstructor/Data/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License along
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Newtonsoft.Json;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static T ParseJson<T>(string path)
}
catch (Exception e)
{
Editor.Log.Write(e.Message);
Editor.Log.Write("Failed to parse file " + path + " because " + e.Message);
return default(T);
}
}
Expand All @@ -68,7 +69,7 @@ public static void SerializeJson<T>(string path, T obj)
}
catch (Exception e)
{
Editor.Log.Write(e.Message);
Editor.Log.Write("Failed to save file " + path + " because " + e.Message);
MessageBox.Show("Failed to save file " + path + ", please try again! Consult the log file for more information.");
}
}
Expand Down
6 changes: 6 additions & 0 deletions Starstructor/EditorAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ private static void RefreshAssetsBackground(bool clearMap = true)

StarboundObject sbObject = JsonParser.ParseJson<StarboundObject>(file);

if (sbObject == null)
continue;

lock (m_objectMap)
{
m_objectMap[sbObject.ObjectName] = sbObject;
Expand All @@ -206,6 +209,9 @@ private static void RefreshAssetsBackground(bool clearMap = true)

StarboundMaterial sbMaterial = JsonParser.ParseJson<StarboundMaterial>(file);

if (sbMaterial == null)
continue;

lock (m_materialMap)
{
m_materialMap[sbMaterial.MaterialName] = sbMaterial;
Expand Down
4 changes: 3 additions & 1 deletion Starstructor/GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,9 @@ private void UpdateImageBox(bool resetZoom, bool resetCamera)
return;
}

EditorMapPart part = GetSelectedPart();
EditorMapPart part = GetSelectedPart();

if (part == null) return;

// If we're displaying the graphic map
if (BottomBarGfxCombo.SelectedIndex == 0)
Expand Down
2 changes: 1 addition & 1 deletion Starstructor/StarboundTypes/Objects/ObjectImageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public string GetFrameKey(string frame = "default", string colour = "default", s

public Rectangle? GetImageFrame(string frame = "default", string colour = "default", string key = "default")
{
if (m_image.ImageFile == null)
if (m_image == null || m_image.ImageFile == null)
return null;

if (m_frames == null)
Expand Down
12 changes: 10 additions & 2 deletions Starstructor/StarboundTypes/StarboundDungeon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ public override void LoadParts(Editor parent)
Editor.Log.Write(" Layer image " + fileName + " loaded");
}

int width = part.Width*Editor.DEFAULT_GRID_FACTOR;
int height = part.Height*Editor.DEFAULT_GRID_FACTOR;

if (width <= 0)
width = 1;

if (height <= 0)
height = 1;

// Create the graphics image
part.GraphicsMap = new Bitmap(part.Width*Editor.DEFAULT_GRID_FACTOR,
part.Height*Editor.DEFAULT_GRID_FACTOR, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
part.GraphicsMap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

// Update the composite collision map, now that all layers have been loaded
part.UpdateCompositeCollisionMap();
Expand Down

0 comments on commit 0e39c2d

Please sign in to comment.