Commit ec99fa95 authored by H1Gdev's avatar H1Gdev Committed by mrbean-bremen
Browse files

Fix: Crash viewer when entering text.

- Catch exceptions in event handler.
parent 838008c1
...@@ -22,28 +22,40 @@ namespace SVGViewer ...@@ -22,28 +22,40 @@ namespace SVGViewer
private void open_Click(object sender, EventArgs e) private void open_Click(object sender, EventArgs e)
{ {
if (openSvgFile.ShowDialog() == DialogResult.OK) try
{
if (openSvgFile.ShowDialog() == DialogResult.OK)
{
SvgDocument svgDoc = SvgDocument.Open(openSvgFile.FileName);
RenderSvg(svgDoc);
}
}
catch
{ {
SvgDocument svgDoc = SvgDocument.Open(openSvgFile.FileName);
RenderSvg(svgDoc);
} }
} }
private void textBox1_TextChanged(object sender, EventArgs e) private void textBox1_TextChanged(object sender, EventArgs e)
{ {
using(var s = new MemoryStream(Encoding.UTF8.GetBytes(textBox1.Text))) try
{ {
SvgDocument svgDoc = SvgDocument.Open<SvgDocument>(s, null); using (var s = new MemoryStream(Encoding.UTF8.GetBytes(textBox1.Text)))
RenderSvg(svgDoc); {
} SvgDocument svgDoc = SvgDocument.Open<SvgDocument>(s, null);
RenderSvg(svgDoc);
}
}
catch
{
}
} }
private void RenderSvg(SvgDocument svgDoc) private void RenderSvg(SvgDocument svgDoc)
{ {
//var render = new DebugRenderer(); //var render = new DebugRenderer();
//svgDoc.Draw(render); //svgDoc.Draw(render);
svgImage.Image = svgDoc.Draw(); svgImage.Image = svgDoc.Draw();
string outputDir; string outputDir;
if (svgDoc.BaseUri == null) if (svgDoc.BaseUri == null)
outputDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath); outputDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment