/[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/15 21:50:56	79
+++ trunk/gr2lib/core/coretypes/implementation/Texture.cs	2010/07/16 23:35:21	86
@@ -17,7 +17,7 @@
         private int _SubFormat;
         private Layout _Layout;
         private List<Image> _Images;
-        private IntPtr _ExtendedData;
+
 
         
 
@@ -31,42 +31,60 @@
             this.SubFormat = 0;
             this.Layout = new Layout();
             this.Images = new List<Image>();
-            this.ExtendedData = IntPtr.Zero;
-            this.NativePointer = IntPtr.Zero;
+            //this.ExtendedData = new IntPtr();
+            //this.NativePointer = IntPtr.Zero;
         }
 
         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
@@ -78,12 +96,16 @@
         public int SubFormat { get { return _SubFormat; } set { _SubFormat = value; } }
         public Layout Layout { get { return _Layout; } set { _Layout = value; } }
         public List<Image> Images { get { return _Images; } set { _Images = value; } }
-        public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
         #endregion
 
         #region INativePointer Members
         private IntPtr _NativePointer;
         public IntPtr NativePointer { get { return _NativePointer; } set { _NativePointer = value; } }
         #endregion
+
+        #region IExtendedData Members
+        private IntPtr _ExtendedData;
+        public IntPtr ExtendedData { get { return _ExtendedData; } set { _ExtendedData = value; } }
+        #endregion
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22