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

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

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

--- trunk/gr2lib/core/coretypes/implementation/Image.cs	2010/07/15 21:50:56	79
+++ trunk/gr2lib/core/coretypes/implementation/Image.cs	2010/07/16 23:35:21	86
@@ -13,33 +13,51 @@
         public Image()
         {
             this.MIPLevels = new List<MIPLevel>();
-            this.NativePointer = IntPtr.Zero;
+            //this.NativePointer = IntPtr.Zero;
         }
 
         internal static Image ReadFromMemory(IntPtr pointer)
         {
+            try 
+            { 
             if (pointer == IntPtr.Zero) return null;
             native.Image native = Helpers.ReadFromMemory<native.Image>(pointer);
             Image managed = ReadFromNative(native);
             managed.NativePointer = pointer;
             return managed;
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+                return default(Image);
+            }
         }
 
         internal static Image ReadFromNative(native.Image native)
         {
-            Image managed = new Image();
-            IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
-            int length = miplevels.Length;
-            managed.MIPLevels = new List<MIPLevel>(length);
-            foreach (IntPtr ptr in miplevels)
+            try
             {
-                managed.MIPLevels.Add(new MIPLevel());
+                Image managed = new Image();
+                IntPtr[] miplevels = Helpers.ReadPtrArrayFromMemory<native.MIPLevel>(native.MIPLevels);
+                int length = miplevels.Length;
+                managed.MIPLevels = new List<MIPLevel>(length);
+                foreach (IntPtr ptr in miplevels)
+                {
+                    MIPLevel _tmp = new MIPLevel();
+                    _tmp.NativePointer = ptr;
+                    managed.MIPLevels.Add(_tmp);
+                }
+                for (int i = 0; i < length; i++)
+                {
+                    managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
+                }
+                return managed;
             }
-            for (int i = 0; i < length; i++)
+            catch (Exception ex)
             {
-                managed.MIPLevels[i] = MIPLevel.ReadFromMemory(miplevels[i]);
+                Console.WriteLine(ex.ToString());
+                return default(Image);
             }
-            return managed;
         }
 
         #region INativePointer Members

 

  ViewVC Help
Powered by ViewVC 1.1.22