Davaris Posted July 9, 2010 Share Posted July 9, 2010 I just noticed this function doesn't return null, if it fails to find a file. Is there another way to check if it succeeded or failed? public static Mesh Load(string path) { return new Mesh(Core.LoadMesh(path, Entity.NullPointer)); } Quote Win 7 Pro 64 bit AMD Phenom II X3 720 2.8GHz GeForce 9800 GTX/9800 GTX+ 4 GB RAM Link to comment Share on other sites More sharing options...
ZioRed Posted July 9, 2010 Share Posted July 9, 2010 Check the Pointer of the mesh: Mesh mesh = Mesh.Load("abstract::mymesh.gmf"); if (mesh.Pointer == IntPtr.Zero) { // mesh not found } Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Davaris Posted July 9, 2010 Author Share Posted July 9, 2010 Thanks. Quote Win 7 Pro 64 bit AMD Phenom II X3 720 2.8GHz GeForce 9800 GTX/9800 GTX+ 4 GB RAM Link to comment Share on other sites More sharing options...
Rick Posted July 9, 2010 Share Posted July 9, 2010 Not that it's a huge deal, but that seems kind of hacky. Would seem better if we could just check the Mesh object against null. Quote Link to comment Share on other sites More sharing options...
ZioRed Posted July 9, 2010 Share Posted July 9, 2010 I dislike any *.Load method and would prefer to have a constructor instead. I also think that you will never have an invalid filepath in your game unless the player has hacked it (which you should check before the game is loaded with FileSystem.GetAbsolutePath). Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Rick Posted July 9, 2010 Share Posted July 9, 2010 I agree that it should load in the constructor, but would still like to check the object against null instead of the .Pointer variable. A file might have been deleted, so I think checking for null after loading is something that should still happen. Quote Link to comment Share on other sites More sharing options...
TylerH Posted July 9, 2010 Share Posted July 9, 2010 This may be changed over in the future to do as you guys suggest, but right now the only C# system that will handle loading and such in the constructor, as well as null checks and thread safety is my GameEntity class; unfortunately, it isn't close to being finished or fully usable. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
TylerH Posted July 9, 2010 Share Posted July 9, 2010 Question: Maybe some custom exceptions could be thrown ? public static Mesh Load(string path) { try { Mesh mesh = new Mesh(Core.LoadMesh(path, Entity.NullPointer)); } catch (mesh.Pointer == Entity.NullPointer) { throw new LeadwerksNullEntityException(); } } Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
ZioRed Posted July 9, 2010 Share Posted July 9, 2010 but would still like to check the object against null instead of the .Pointer variable. I forgot that you can check against Entity.Null instead of null, this is how also the NET System.Data works (with DBNull.Value): if (entity == Entity.Null) { // Wrong entity } Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Rick Posted July 9, 2010 Share Posted July 9, 2010 I don't think Mesh should have a Load() method. It should be in the ctor I think. Quote Link to comment Share on other sites More sharing options...
TylerH Posted July 9, 2010 Share Posted July 9, 2010 I am seeing it. I will go ahead and switch that over. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
TylerH Posted July 9, 2010 Share Posted July 9, 2010 I don't think Mesh should have a Load() method. It should be in the ctor I think. Rick do you have MSN? Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Rick Posted July 9, 2010 Share Posted July 9, 2010 I do, but I'm at work at the moment and can't access it here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.