Sign in to follow this  
no hit wonder

The need for consistant fault checking

Recommended Posts

This doesn't really have anything to do with games specifically, so I'm posting it here instead. I was curious of everyone's opinion regarding the need to continuously check for correctness of data. The question occured to me when I was looking at someone elses code that used my code as a lower level layer, and specifically the segment that loaded a mesh brought it to my attention most. Here is generally the process he used to load a mesh Check to see if the resource manager has been initialized Check to see if the resource type had been registered Check to see if the file IO system had been initialized Check to see if the file type had been registered Check to see if Direct3D had been initialized Check to see if the vertex buffer has been initialized Call the mesh loading function, and check to see if it succeeded. Obviously the last line is needed, and his reason for adding all the others in there was that he looked at my code and noticed that none of the other stuff was checked by the mesh loading function, which he was both concerned and disappointed by. But I'm wondering, since it is only possible to get to the point of loading meshes without everything else having been already initialized, if you intentionally work around all the frame work I've put in place. Realisticly it doesn't need to do all this checking, and all it does is take up a hundred or so lines of code with ugly 'if-else' statement pairs. So my question, do you feel it is actually necessary to check for errors every step of the way, or do you feel that the state of the system can be assumed to be safe, when reasonable. You should always check to see if a given value is correct when it is coming from outside your system [like, froma file], but data that is exchanged within your program, do you feel the need to check it?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by no hit wonder
...since it is only possible to get to the point of loading meshes without everything else having been already initialized...

I think this is the crunch point. Is this always the case? what would happen if any of the parts were not initialised? would the function throw an error, fail to succeed gracefully(ie not a bork)?

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by no hit wonder
...since it is only possible to get to the point of loading meshes without everything else having been already initialized...

I think this is the crunch point. Is this always the case? what would happen if any of the parts were not initialised? would the function throw an error, fail to succeed gracefully(ie not a bork)?
Well, if all this checking wasn't done, and the function was called without the initialization being called first, it would fail in a rather bad way and would likely result in a straight-out crash [specifically dereferencing null pointers], but all the components that are needed would be loaded previous to even having the opportunity to be called, and would result in a shutdown of the program, and a detailed description of the error. To call the 'load mesh' function previous to all the other steps being taken would require changing the source code of the engine.

Share this post


Link to post
Share on other sites
With a good design, this wouldn't be necessary.

Pass the mesh-loading-function an object representing a loader, by reference. So, to call the mesh-loading-function, you need to have a loader, or you won't be able to call it. Make sure the loader constructor throws an exception if there is an error when initializing it. There you go: you're ensuring at compile-time that everything works correctly (the only way to have a loader is to correctly initialize it, the only way to load a model is to have a loader), and compile-time checks are a Very Good ThingTM.

Sprinkle with debug-version runtime checks (such as asserts) to check for valid internal state of objects (just in case you screw up), and remove them in production to get maximum performance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this