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

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

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

--- trunk/gr2lib/core/coretypes/implementation/Material.cs	2010/07/16 21:26:08	83
+++ trunk/gr2lib/core/coretypes/implementation/Material.cs	2010/07/16 23:35:21	86
@@ -6,7 +6,7 @@
 using gr2lib.core.interfaces;
 namespace gr2lib.core.coretypes.implementation
 {
-   
+
 
     public class Material : IMaterial
     {
@@ -17,36 +17,52 @@
             this.Name = "";
             this.Maps = new List<Map>();
             this.Texture = new Texture();
-           
+
         }
 
-       internal static Material ReadFromMemory(IntPtr pointer)
+        internal static Material ReadFromMemory(IntPtr pointer)
         {
-            if (pointer == IntPtr.Zero) return null;
-            native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
-            Material managed = ReadFromNative(native);
-            managed.NativePointer = pointer;
-            return managed;
+            try
+            {
+                if (pointer == IntPtr.Zero) return null;
+                native.Material native = Helpers.ReadFromMemory<native.Material>(pointer);
+                Material managed = ReadFromNative(native);
+                managed.NativePointer = pointer;
+                return managed;
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+                return default(Material);
+            }
         }
 
         internal static Material ReadFromNative(native.Material native)
         {
-            Material managed = new Material();
-            managed.Name = native.Name;
-            IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
-            int length = maps.Length;
-            managed.Maps = new List<Map>(length);
-            foreach (IntPtr ptr in maps)
+            try
             {
-                managed.Maps.Add(new Map());
+                Material managed = new Material();
+                managed.Name = native.Name;
+                IntPtr[] maps = Helpers.ReadPtrArrayFromMemory<native.Map>(native.Maps);
+                int length = maps.Length;
+                managed.Maps = new List<Map>(length);
+                foreach (IntPtr ptr in maps)
+                {
+                    managed.Maps.Add(new Map());
+                }
+                for (int i = 0; i < length; i++)
+                {
+                    managed.Maps[i] = Map.ReadFromMemory(maps[i]);
+                }
+                managed.Texture = Texture.ReadFromMemory(native.Texture);
+                managed.ExtendedData = native.ExtendedData;
+                return managed;
             }
-            for (int i = 0; i < length; i++)
+            catch (Exception ex)
             {
-                managed.Maps[i] = Map.ReadFromMemory(maps[i]);
+                Console.WriteLine(ex.ToString());
+                return default(Material);
             }
-            managed.Texture = Texture.ReadFromMemory(native.Texture);
-            managed.ExtendedData = native.ExtendedData;
-            return managed;
         }
 
         #region INativePointer Members
@@ -60,7 +76,7 @@
         private Texture _Texture;
         public string Name { get { return _Name; } set { _Name = value; } }
         public List<Map> Maps { get { return _Maps; } set { _Maps = value; } }
-        public Texture Texture { get { return _Texture; } set { _Texture = value; } } 
+        public Texture Texture { get { return _Texture; } set { _Texture = value; } }
         public bool IsTexture { get { if (Texture == null) { return false; } else { return true; } } }
         #endregion
 

 

  ViewVC Help
Powered by ViewVC 1.1.22