Game Development Reference
In-Depth Information
{
// Unregister events
// get rid of managed resources here
if (m_DirectInput != null)
m_DirectInput.Dispose();
if (m_Keyboard != null)
m_Keyboard.Dispose();
if (m_Mouse != null)
m_Mouse.Dispose();
}
// get rid of unmanaged resources here
}
m_bDisposed = true;
}
As you can see, the internal structure of this method is identical to the one we cre-
ated in the GameWindow class. It has the same if statements inside it. The differ-
ence is that this time, we don't have an event to unhook, and we've added code to
dispose of our DirectInput, keyboard, and mouse objects in the managed resources
section of this method.
So, why is each of these objects disposed of inside its own little if statement? The
reason for this is to prevent a potential crash that would happen if one of these ob-
jects is for some reason null. So, we check to see if the object is null. If it is not, then
we dispose of it. Calling dispose on an object that is null will cause a Null Reference
exception.
Now, we just have a few properties to add to our user input class. They are all very
simple, and they just provide access to our member variables. Here are two of these
properties. Check out the downloadable code for this chapter to see all of them.
Search WWH ::




Custom Search