/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/Texture.cs
ViewVC logotype

Diff of /trunk/gr2lib/core/coretypes/implementation/Texture.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/gr2lib/core/coretypes/implementation/Texture.cs	2010/07/16 21:26:08	83
+++ trunk/gr2lib/core/coretypes/implementation/Texture.cs	2010/07/16 23:35:21	86
@@ -37,36 +37,54 @@
 
         internal static Texture ReadFromMemory(IntPtr pointer)
         {
+            try 
+            {
             if (pointer == IntPtr.Zero) return null;
             native.Texture native = Helpers.ReadFromMemory<native.Texture>(pointer);
             Texture managed = ReadFromNative(native);
             managed.NativePointer = pointer;
             return managed;
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+                return default(Texture);
+            }
         }
 
         internal static Texture ReadFromNative(native.Texture native)
         {
-            Texture managed = new Texture();
-            managed.FromFileName = native.FromFileName;
-            managed.TextureType = native.TextureType;
-            managed.Width = native.Width;
-            managed.Height = native.Height;
-            managed.Encoding = native.Encoding;
-            managed.SubFormat = native.SubFormat;
-            managed.Layout = Layout.ReadFromNative(native.Layout);
-            IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
-            int length = images.Length;
-            managed.Images = new List<Image>(length);
-            foreach (IntPtr ptr in images)
+            try
             {
-                managed.Images.Add(new Image());
+                Texture managed = new Texture();
+                managed.FromFileName = native.FromFileName;
+                managed.TextureType = native.TextureType;
+                managed.Width = native.Width;
+                managed.Height = native.Height;
+                managed.Encoding = native.Encoding;
+                managed.SubFormat = native.SubFormat;
+                managed.Layout = Layout.ReadFromNative(native.Layout);
+                IntPtr[] images = Helpers.ReadPtrArrayFromMemory<native.Image>(native.Images);
+                int length = images.Length;
+                managed.Images = new List<Image>(length);
+                foreach (IntPtr ptr in images)
+                {
+                    Image _tmp = new Image();
+                    _tmp.NativePointer = ptr;
+                    managed.Images.Add(_tmp);
+                }
+                for (int i = 0; i < length; i++)
+                {
+                    managed.Images[i] = Image.ReadFromMemory(images[i]);
+                }
+                managed.ExtendedData = native.ExtendedData;
+                return managed;
             }
-            for (int i = 0; i < length; i++)
+            catch (Exception ex)
             {
-                managed.Images[i] = Image.ReadFromMemory(images[i]);
+                Console.WriteLine(ex.ToString());
+                return default(Texture);
             }
-            managed.ExtendedData = native.ExtendedData;
-            return managed;
         }
 
         #region ITexture Members

 

  ViewVC Help
Powered by ViewVC 1.1.22