So I'm borrowing a lot of code from many places, but I can't figure out this error for the life of me.
So I'm using the InputManger.h/InputManager.cpp code from here:
http://www.ogre3d.org/wiki/index.php/Using_OISBut I changed it so that I could mess around with an already open window (I want to build a gui on top of a game to help keep track of stats in game). Point is, I'm trying to use OIS to log my keystrokes/mouse input. So I'd like to initialize OIS on a different window. As a proof of concept, I was working on getting it working with Notepad, so my program opens notepad before calling the inputmanager constructor and initialize. So I modified InputManager.h/InputManager.cpp in the following way (I changed initialise[sic]):
void InputManager::initialise(std::string winTitle) {
if( !mInputSystem) {
// Setup basic variables
OIS::ParamList paramList; //I was initially going to use OIS createinputobject using the paramList, but that didn't work so I used just the window
//handle. However, I looked at the source code, and the createinputobject code just creates a param entry anyways
// Get window handle
HWND Calc = FindWindow(NULL,L"Untitled - Notepad");
// Fill parameter list
unsigned int t = (unsigned int) Calc;
// paramList.insert( std::make_pair( "WINDOW", windowHndStr.str() ) ); //ignore this, it's old code, sorry
// Create inputsystem
mInputSystem = OIS::InputManager::createInputSystem((size_t) Calc); //I checked the handle, and it seemed to be working just fine
// If possible create a buffered keyboard
try{
int b2 = mInputSystem->getNumberOfDevices(OIS::OISKeyboard); //originally this was my problem, not anymore
}
catch(OIS::Exception &e)
{
std::cout << e.eText << std::endl;
}
int b2 = mInputSystem->getNumberOfDevices(OIS::OISKeyboard);
//int t2 = mInputSystem->numKeyboards() ;
if (mInputSystem->getNumberOfDevices(OIS::OISKeyboard) > 0) {
mKeyboard = static_cast<OIS::Keyboard*>( mInputSystem->createInputObject( OIS::OISKeyboard, true ) );
mKeyboard->setEventCallback( this );
}
// If possible create a buffered mouse
// (note: if below line doesn't compile, try: if (mInputSystem->getNumberOfDevices(OIS::OISMouse) > 0) {
//if( mInputSystem->numMice() > 0 ) {
if (mInputSystem->getNumberOfDevices(OIS::OISMouse) > 0) {
mMouse = static_cast<OIS::Mouse*>( mInputSystem->createInputObject( OIS::OISMouse, true ) );
mMouse->setEventCallback( this );
// Get window size
// Set mouse region
this->setWindowExtents( AU3_WinGetClientSizeHeight(stringConvert(winTitle)->c_str(),TEXT(""))
,AU3_WinGetClientSizeWidth(stringConvert(winTitle)->c_str(), TEXT("")));
}
// If possible create all joysticks in buffered mode
// (note: if below line doesn't compile, try: if (mInputSystem->getNumberOfDevices(OIS::OISJoyStick) > 0) {
//if( mInputSystem->numJoySticks() > 0 ) {
if (mInputSystem->getNumberOfDevices(OIS::OISJoyStick) > 0) {
//mJoysticks.resize( mInputSystem->numJoySticks() );
mJoysticks.resize( mInputSystem->getNumberOfDevices(OIS::OISJoyStick) );
itJoystick = mJoysticks.begin();
itJoystickEnd = mJoysticks.end();
for(; itJoystick != itJoystickEnd; ++itJoystick ) {
(*itJoystick) = static_cast<OIS::JoyStick*>( mInputSystem->createInputObject( OIS::OISJoyStick, true ) );
(*itJoystick)->setEventCallback( this );
}
}
}
}The weirdest part is, when I try to run it and I put code breaks in and I use visual studio to step through the program, everything runs fine. If I try to run it without any code breaks I get this: Unhandled exception at 0x776242eb in AppSpy.exe: Microsoft C++ exception: OIS::Exception at memory location 0x0018eebc..
I really have no idea why this is happening, anything you can think of would be greatly appreciated.
Thanks guys.