gbrainy r454 - trunk/src



Author: jmas
Date: Sat Aug 30 10:17:31 2008
New Revision: 454
URL: http://svn.gnome.org/viewvc/gbrainy?rev=454&view=rev

Log:
Better SVG error handeling

Modified:
   trunk/src/ChangeLog
   trunk/src/GameDrawingArea.cs
   trunk/src/SVGImage.cs

Modified: trunk/src/GameDrawingArea.cs
==============================================================================
--- trunk/src/GameDrawingArea.cs	(original)
+++ trunk/src/GameDrawingArea.cs	Sat Aug 30 10:17:31 2008
@@ -88,9 +88,15 @@
 
 	private void DrawImage (CairoContextEx gr, double x, double y, string img)
 	{
-		SVGImage image = new SVGImage (img);
-		if (image == null)
+		SVGImage image;
+
+		try {
+			image = new SVGImage (img);
+		}
+		catch (Exception e)
+		{
 			return;
+		}
 
 		gr.Save ();
 		gr.Translate (x, y);

Modified: trunk/src/SVGImage.cs
==============================================================================
--- trunk/src/SVGImage.cs	(original)
+++ trunk/src/SVGImage.cs	Sat Aug 30 10:17:31 2008
@@ -56,14 +56,22 @@
 	public SVGImage (string file)
 	{
 		int error = 0;
+		dimension = new RsvgDimensionData ();
 
-		handle = rsvg_handle_new_from_file (file, out error);
+		try {
+			handle = rsvg_handle_new_from_file (file, out error);
 
-		if (handle == IntPtr.Zero)
-			throw new System.IO.IOException ("File not found: " + file);
+			if (handle != IntPtr.Zero)		
+				rsvg_handle_get_dimensions (handle, ref dimension);
 
-		dimension = new RsvgDimensionData ();
-		rsvg_handle_get_dimensions (handle, ref dimension);
+		}
+
+		finally
+		{
+			if (handle == IntPtr.Zero)
+				throw new System.IO.IOException ("File not found: " + file);
+
+		}
 	}
 
 	public int Width {
@@ -85,7 +93,8 @@
 
 	public void RenderToCairo (IntPtr cairo_surface)
 	{
-		rsvg_handle_render_cairo (handle, cairo_surface);
+		if (handle != IntPtr.Zero)
+			rsvg_handle_render_cairo (handle, cairo_surface);
 	}
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]