Original Post
Hey everyone! Im currently writing an input manager for my game using DirectInput. I decided to use a singleton as there should only be one instance. This is causing me problems. Heres my class: My question is: How do I access/use m_pDirectInput? That is, I am getting a memory access violation with this code.. I cant seem to find out what is wrong. m_pDirectInput is nulled out in the constructor. m_pInstance is also allocated in the constructor. Everything worked okay before I added the singleton code. Also, Although I null out m_pDirectInput in the constructor, my debugger doesnt say that. I believe this is the source of my problem--but I cant find a solution! Im sure its probably something simple Im missing.. Please help! Any help is appreciated! Thanks in advance!
class cInput
{
static cInput* m_pInstance;
IDirectInput8* m_pDirectInput;
//etc.
cInput ();
~cInput ();
public:
static cInput* GetInstance ()
{
return m_pInstance;
}
bool Initialize ();
};
// I initialize the class like this:
if (! cInput::GetInstance()->Initialize () )
{
}
// The initialize method..
bool cInput::Initialize ()
{
// dont recreate DirectInput!
if (m_pDirectInput) // *** MEMORY ACCESS VIOLATION ***
return true;
// init DirectInput
}